Skip to content

Commit 88d351e

Browse files
authored
[clang-format] Fix a regression in annotating struct braces (#92352)
Fixes #92350.
1 parent 8fe39e6 commit 88d351e

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4008,18 +4008,20 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
40084008
};
40094009

40104010
if (FormatTok->isOneOf(tok::colon, tok::less)) {
4011-
if (FormatTok->is(tok::colon))
4012-
IsDerived = true;
40134011
int AngleNestingLevel = 0;
40144012
do {
40154013
if (FormatTok->is(tok::less))
40164014
++AngleNestingLevel;
40174015
else if (FormatTok->is(tok::greater))
40184016
--AngleNestingLevel;
40194017

4020-
if (AngleNestingLevel == 0 && FormatTok->is(tok::l_paren) &&
4021-
IsNonMacroIdentifier(FormatTok->Previous)) {
4022-
break;
4018+
if (AngleNestingLevel == 0) {
4019+
if (FormatTok->is(tok::colon)) {
4020+
IsDerived = true;
4021+
} else if (FormatTok->is(tok::l_paren) &&
4022+
IsNonMacroIdentifier(FormatTok->Previous)) {
4023+
break;
4024+
}
40234025
}
40244026
if (FormatTok->is(tok::l_brace)) {
40254027
if (AngleNestingLevel == 0 && IsListInitialization())

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,6 +2903,11 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
29032903
EXPECT_BRACE_KIND(Tokens[5], BK_Block);
29042904
EXPECT_BRACE_KIND(Tokens[6], BK_Block);
29052905

2906+
Tokens = annotate("struct Foo<int> : Base {};");
2907+
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
2908+
EXPECT_BRACE_KIND(Tokens[7], BK_Block);
2909+
EXPECT_BRACE_KIND(Tokens[8], BK_Block);
2910+
29062911
Tokens = annotate("struct Foo final {};");
29072912
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
29082913
EXPECT_BRACE_KIND(Tokens[3], BK_Block);

0 commit comments

Comments
 (0)