From 8031242e600e1b01b54b4d44d6a510467febfda6 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Sun, 23 Nov 2025 20:53:21 -0800 Subject: [PATCH] [clang-format] Handle `import` when used as template function name Fixes #149960 --- clang/lib/Format/TokenAnnotator.cpp | 5 ++++- clang/unittests/Format/FormatTest.cpp | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) 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) {