Skip to content

Commit 0fa78b6

Browse files
authored
[clang-format] Correctly annotate braces in macro definition (llvm#106662)
Fixes llvm#106418.
1 parent 34b10e1 commit 0fa78b6

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,8 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
609609
ProbablyBracedList = NextTok->isNot(tok::l_square);
610610
}
611611

612-
// Cpp macro definition body that is a nonempty braced list or block:
612+
// Cpp macro definition body containing nonempty braced list or block:
613613
if (IsCpp && Line->InMacroBody && PrevTok != FormatTok &&
614-
!FormatTok->Previous && NextTok->is(tok::eof) &&
615614
// A statement can end with only `;` (simple statement), a block
616615
// closing brace (compound statement), or `:` (label statement).
617616
// If PrevTok is a block opening brace, Tok ends an empty block.

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,6 +3256,11 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
32563256
EXPECT_BRACE_KIND(Tokens[10], BK_Block);
32573257
EXPECT_TOKEN(Tokens[11], tok::r_brace, TT_StructRBrace);
32583258
EXPECT_BRACE_KIND(Tokens[11], BK_Block);
3259+
3260+
Tokens = annotate("#define MEMBER(NAME) NAME{\"\"}");
3261+
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
3262+
EXPECT_BRACE_KIND(Tokens[7], BK_BracedInit);
3263+
EXPECT_BRACE_KIND(Tokens[9], BK_BracedInit);
32593264
}
32603265

32613266
TEST_F(TokenAnnotatorTest, UnderstandsElaboratedTypeSpecifier) {

0 commit comments

Comments
 (0)