[clang] 88d351e - [clang-format] Fix a regression in annotating struct braces (#92352)
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 16 19:24:38 PDT 2024
Author: Owen Pan
Date: 2024-05-16T19:24:35-07:00
New Revision: 88d351e2e62d2ff291f3e6dea6b7e425f683285b
URL: https://github.com/llvm/llvm-project/commit/88d351e2e62d2ff291f3e6dea6b7e425f683285b
DIFF: https://github.com/llvm/llvm-project/commit/88d351e2e62d2ff291f3e6dea6b7e425f683285b.diff
LOG: [clang-format] Fix a regression in annotating struct braces (#92352)
Fixes #92350.
Added:
Modified:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 2236a49e4b765..b15a87327240b 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -4008,8 +4008,6 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
};
if (FormatTok->isOneOf(tok::colon, tok::less)) {
- if (FormatTok->is(tok::colon))
- IsDerived = true;
int AngleNestingLevel = 0;
do {
if (FormatTok->is(tok::less))
@@ -4017,9 +4015,13 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
else if (FormatTok->is(tok::greater))
--AngleNestingLevel;
- if (AngleNestingLevel == 0 && FormatTok->is(tok::l_paren) &&
- IsNonMacroIdentifier(FormatTok->Previous)) {
- break;
+ if (AngleNestingLevel == 0) {
+ if (FormatTok->is(tok::colon)) {
+ IsDerived = true;
+ } else if (FormatTok->is(tok::l_paren) &&
+ IsNonMacroIdentifier(FormatTok->Previous)) {
+ break;
+ }
}
if (FormatTok->is(tok::l_brace)) {
if (AngleNestingLevel == 0 && IsListInitialization())
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 51b475d37977e..aadfa6dc0165c 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2903,6 +2903,11 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
EXPECT_BRACE_KIND(Tokens[5], BK_Block);
EXPECT_BRACE_KIND(Tokens[6], BK_Block);
+ Tokens = annotate("struct Foo<int> : Base {};");
+ ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+ EXPECT_BRACE_KIND(Tokens[7], BK_Block);
+ EXPECT_BRACE_KIND(Tokens[8], BK_Block);
+
Tokens = annotate("struct Foo final {};");
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
EXPECT_BRACE_KIND(Tokens[3], BK_Block);
More information about the cfe-commits
mailing list