Skip to content

Commit 9a692e0

Browse files
authored
[clang-format] Don't annotate class property specifiers as StartOfName (#153525)
Fixes #153443
1 parent 350cb98 commit 9a692e0

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,6 +2590,9 @@ class AnnotatingParser {
25902590
if (!Tok.Previous || Tok.isNot(tok::identifier) || Tok.is(TT_ClassHeadName))
25912591
return false;
25922592

2593+
if (Tok.endsSequence(Keywords.kw_final, TT_ClassHeadName))
2594+
return false;
2595+
25932596
if ((Style.isJavaScript() || Style.isJava()) && Tok.is(Keywords.kw_extends))
25942597
return false;
25952598

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsStructs) {
618618
EXPECT_TOKEN(Tokens[19], tok::l_brace, TT_StructLBrace);
619619
EXPECT_TOKEN(Tokens[20], tok::r_brace, TT_StructRBrace);
620620

621+
Tokens = annotate("class Outer {\n"
622+
" struct Inner final : Base {};\n"
623+
"};");
624+
ASSERT_EQ(Tokens.size(), 14u) << Tokens;
625+
EXPECT_TOKEN(Tokens[5], tok::identifier, TT_Unknown); // Not TT_StartOfName
626+
EXPECT_TOKEN(Tokens[6], tok::colon, TT_InheritanceColon);
627+
621628
constexpr StringRef Code("struct EXPORT StructName {};");
622629

623630
Tokens = annotate(Code);

0 commit comments

Comments
 (0)