Skip to content

Conversation

owenca
Copy link
Contributor

@owenca owenca commented Aug 14, 2025

Fixes #153443

@llvmbot
Copy link
Member

llvmbot commented Aug 14, 2025

@llvm/pr-subscribers-clang-format

Author: owenca (owenca)

Changes

Fixes #153443


Full diff: https://github.com/llvm/llvm-project/pull/153525.diff

2 Files Affected:

  • (modified) clang/lib/Format/TokenAnnotator.cpp (+3)
  • (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+7)
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 4801d27b1395a..88752903914bf 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2590,6 +2590,9 @@ class AnnotatingParser {
     if (!Tok.Previous || Tok.isNot(tok::identifier) || Tok.is(TT_ClassHeadName))
       return false;
 
+    if (Tok.endsSequence(Keywords.kw_final, TT_ClassHeadName))
+      return false;
+
     if ((Style.isJavaScript() || Style.isJava()) && Tok.is(Keywords.kw_extends))
       return false;
 
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 7f99655b1fa49..85ccba38ac8ca 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -618,6 +618,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsStructs) {
   EXPECT_TOKEN(Tokens[19], tok::l_brace, TT_StructLBrace);
   EXPECT_TOKEN(Tokens[20], tok::r_brace, TT_StructRBrace);
 
+  Tokens = annotate("class Outer {\n"
+                    "  struct Inner final : Base {};\n"
+                    "};");
+  ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::identifier, TT_Unknown); // Not TT_StartOfName
+  EXPECT_TOKEN(Tokens[6], tok::colon, TT_InheritanceColon);
+
   constexpr StringRef Code("struct EXPORT StructName {};");
 
   Tokens = annotate(Code);

@owenca owenca added this to the LLVM 21.x Release milestone Aug 14, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Aug 14, 2025
@owenca owenca changed the title [clang-format] Don't annotate class specifiers as StartOfName [clang-format] Don't annotate class property specifiers as StartOfName Aug 16, 2025
@github-project-automation github-project-automation bot moved this from Needs Triage to Needs Merge in LLVM Release Status Aug 17, 2025
@owenca owenca merged commit 9a692e0 into llvm:main Aug 17, 2025
11 checks passed
@owenca owenca deleted the 153443 branch August 17, 2025 19:53
@github-project-automation github-project-automation bot moved this from Needs Merge to Done in LLVM Release Status Aug 17, 2025
@owenca
Copy link
Contributor Author

owenca commented Aug 17, 2025

/cherry-pick 9a692e0

@llvmbot
Copy link
Member

llvmbot commented Aug 17, 2025

Failed to cherry-pick: 9a692e0

https://github.com/llvm/llvm-project/actions/runs/17025259697

Please manually backport the fix and push it to your github fork. Once this is done, please create a pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

[clang-format] inner final classes are not formatted correctly

3 participants