[clang] [clang-format] Handle `import` when used as template function name (PR #169279)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 23 20:54:10 PST 2025
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/169279
Fixes #149960
>From 8031242e600e1b01b54b4d44d6a510467febfda6 Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
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 <iostream>.
// 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<engine_module>();");
}
TEST_F(FormatTest, CoroutineForCoawait) {
More information about the cfe-commits
mailing list