[clang] 3a522ff - [clang-format] Followup cleanup after #199459 (#202104)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 7 13:55:36 PDT 2026
Author: owenca
Date: 2026-06-07T13:55:31-07:00
New Revision: 3a522ff09cba85bb20275123b598d06408f9e21f
URL: https://github.com/llvm/llvm-project/commit/3a522ff09cba85bb20275123b598d06408f9e21f
DIFF: https://github.com/llvm/llvm-project/commit/3a522ff09cba85bb20275123b598d06408f9e21f.diff
LOG: [clang-format] Followup cleanup after #199459 (#202104)
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 22b41fb337cda..c47a512454476 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2701,6 +2701,7 @@ class AnnotatingParser {
// int a or auto a.
if (PreviousNotConst->isOneOf(tok::identifier, tok::kw_auto) &&
+ !PreviousNotConst->endsSequence(Keywords.kw_import, tok::kw_export) &&
PreviousNotConst->isNot(TT_StatementAttributeLikeMacro)) {
return true;
}
@@ -5227,23 +5228,19 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
(!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)) {
+ // Space between `import :`.
+ if (Left.is(Keywords.kw_import) && Right.is(TT_ModulePartitionColon))
return true;
- }
if (Right.is(TT_AfterPPDirective))
return true;
- // No space between import foo:bar but keep a space between import :bar;
+ // No space between `module foo:bar`.
if (Left.is(tok::identifier) && Right.is(TT_ModulePartitionColon))
return false;
// No space between :bar;
- if (Left.is(TT_ModulePartitionColon) &&
- Right.isOneOf(tok::identifier, tok::kw_private)) {
+ if (Left.is(TT_ModulePartitionColon) && Right.is(tok::identifier))
return false;
- }
if (Left.is(tok::ellipsis) && Right.is(tok::identifier) &&
Line.First->is(Keywords.kw_import)) {
return false;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 48ae9e144cc2a..34106489d7f38 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -3700,6 +3700,10 @@ TEST_F(TokenAnnotatorTest, StartOfName) {
ASSERT_EQ(Tokens.size(), 8u) << Tokens;
EXPECT_TOKEN(Tokens[3], tok::identifier, TT_StartOfName);
+ Tokens = annotate("export import foo;");
+ ASSERT_EQ(Tokens.size(), 5u);
+ EXPECT_TOKEN(Tokens[2], tok::identifier, TT_Unknown); // Not StartOfName
+
auto Style = getLLVMStyle();
Style.StatementAttributeLikeMacros.push_back("emit");
Tokens = annotate("emit foo = 0;", Style);
More information about the cfe-commits
mailing list