-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang-format] Correctly annotate braces in macro definition #106662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) ChangesFixes #106418. Full diff: https://github.com/llvm/llvm-project/pull/106662.diff 2 Files Affected:
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 5b518bf6c859e8..54777c3563cb30 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 5aa5d93c1cb067..136530cf49d253 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -3256,6 +3256,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) {
|
/cherry-pick 0fa78b6 |
Failed to cherry-pick: 0fa78b6 https://github.com/llvm/llvm-project/actions/runs/10663817609 Please manually backport the fix and push it to your github fork. Once this is done, please create a pull request |
/cherry-pick 0fa78b6 |
…6662) Fixes llvm#106418. (cherry picked from commit 0fa78b6)
/pull-request #107058 |
…6662) Fixes llvm#106418. (cherry picked from commit 0fa78b6)
Fixes #106418.