Skip to content

Commit ee23599

Browse files
authored
[clang-format] Fix annotation of braces enclosing stringification (#102998)
Fixes #102937.
1 parent 28050e1 commit ee23599

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
507507
if (!Line->InMacroBody && !Style.isTableGen()) {
508508
// Skip PPDirective lines and comments.
509509
while (NextTok->is(tok::hash)) {
510+
NextTok = Tokens->getNextToken();
511+
if (NextTok->is(tok::pp_not_keyword))
512+
break;
510513
do {
511514
NextTok = Tokens->getNextToken();
512515
} while (NextTok->NewlinesBefore == 0 && NextTok->isNot(tok::eof));

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3216,6 +3216,17 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
32163216
EXPECT_BRACE_KIND(Tokens[17], BK_Block);
32173217
EXPECT_BRACE_KIND(Tokens[22], BK_Block);
32183218
EXPECT_BRACE_KIND(Tokens[26], BK_Block);
3219+
3220+
Tokens = annotate("{\n"
3221+
"#define M(x) \\\n"
3222+
" return {#x};\n"
3223+
"}");
3224+
ASSERT_EQ(Tokens.size(), 15u) << Tokens;
3225+
EXPECT_TOKEN(Tokens[0], tok::l_brace, TT_BlockLBrace);
3226+
EXPECT_BRACE_KIND(Tokens[0], BK_Block);
3227+
EXPECT_BRACE_KIND(Tokens[8], BK_BracedInit);
3228+
EXPECT_BRACE_KIND(Tokens[11], BK_BracedInit);
3229+
EXPECT_BRACE_KIND(Tokens[13], BK_Block);
32193230
}
32203231

32213232
TEST_F(TokenAnnotatorTest, UnderstandsElaboratedTypeSpecifier) {

0 commit comments

Comments
 (0)