diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 19c42c88762fb..200ee13901f4b 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -5033,8 +5033,11 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, return true; // Space between import . // or import .....; - if (Left.is(Keywords.kw_import) && Right.isOneOf(tok::less, tok::ellipsis)) + if (Left.is(Keywords.kw_import) && + Right.isOneOf(tok::less, tok::ellipsis) && + (!BeforeLeft || BeforeLeft->is(tok::kw_export))) { return true; + } // Space between `module :` and `import :`. if (Left.isOneOf(Keywords.kw_module, Keywords.kw_import) && Right.is(TT_ModulePartitionColon)) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 81fa7d1d11aa4..5a5d77075bb3a 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -27328,6 +27328,7 @@ TEST_F(FormatTest, Cpp20ModulesSupport) { verifyFormat("export", Style); verifyFormat("import /* not keyword */ = val ? 2 : 1;"); + verifyFormat("_world->import();"); } TEST_F(FormatTest, CoroutineForCoawait) {