[clang] [clang-format] Fix a regression in annotating struct braces (PR #92352)
via cfe-commits
cfe-commits at lists.llvm.org
Wed May 15 22:49:13 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: Owen Pan (owenca)
<details>
<summary>Changes</summary>
Fixes #<!-- -->92350.
---
Full diff: https://github.com/llvm/llvm-project/pull/92352.diff
2 Files Affected:
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+7-5)
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+5)
``````````diff
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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/92352
More information about the cfe-commits
mailing list