[llvm-branch-commits] [clang] release/19.x: [clang-format] Correctly annotate braces in macro definition (#106662) (PR #107058)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Sep 3 01:44:24 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: None (llvmbot)
<details>
<summary>Changes</summary>
Backport 0fa78b6c7bd43c2498700a98c47a02cf4fd06388
Requested by: @<!-- -->owenca
---
Full diff: https://github.com/llvm/llvm-project/pull/107058.diff
2 Files Affected:
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+1-2)
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+5)
``````````diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 7f5d157ae95891..60e65aaa83e9c1 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -609,9 +609,8 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
ProbablyBracedList = NextTok->isNot(tok::l_square);
}
- // Cpp macro definition body that is a nonempty braced list or block:
+ // Cpp macro definition body containing nonempty braced list or block:
if (IsCpp && Line->InMacroBody && PrevTok != FormatTok &&
- !FormatTok->Previous && NextTok->is(tok::eof) &&
// A statement can end with only `;` (simple statement), a block
// closing brace (compound statement), or `:` (label statement).
// If PrevTok is a block opening brace, Tok ends an empty block.
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index f0533c92f6538c..db580d70058811 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -3218,6 +3218,11 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
EXPECT_BRACE_KIND(Tokens[10], BK_Block);
EXPECT_TOKEN(Tokens[11], tok::r_brace, TT_StructRBrace);
EXPECT_BRACE_KIND(Tokens[11], BK_Block);
+
+ Tokens = annotate("#define MEMBER(NAME) NAME{\"\"}");
+ ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+ EXPECT_BRACE_KIND(Tokens[7], BK_BracedInit);
+ EXPECT_BRACE_KIND(Tokens[9], BK_BracedInit);
}
TEST_F(TokenAnnotatorTest, UnderstandsElaboratedTypeSpecifier) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/107058
More information about the llvm-branch-commits
mailing list