Skip to content

Commit 2d90e8f

Browse files
owencatru
authored andcommitted
[clang-format] Correctly annotate braces in macro definition (#106662)
Fixes #106418. (cherry picked from commit 0fa78b6)
1 parent e594b28 commit 2d90e8f

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
@@ -3218,6 +3218,11 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
32183218
EXPECT_BRACE_KIND(Tokens[10], BK_Block);
32193219
EXPECT_TOKEN(Tokens[11], tok::r_brace, TT_StructRBrace);
32203220
EXPECT_BRACE_KIND(Tokens[11], BK_Block);
3221+
3222+
Tokens = annotate("#define MEMBER(NAME) NAME{\"\"}");
3223+
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
3224+
EXPECT_BRACE_KIND(Tokens[7], BK_BracedInit);
3225+
EXPECT_BRACE_KIND(Tokens[9], BK_BracedInit);
32213226
}
32223227

32233228
TEST_F(TokenAnnotatorTest, UnderstandsElaboratedTypeSpecifier) {

0 commit comments

Comments
 (0)