Skip to content

Commit

Permalink
[clang-format] Fix annotation of braces enclosing stringification (ll…
Browse files Browse the repository at this point in the history
  • Loading branch information
owenca authored and bwendling committed Aug 15, 2024
1 parent cfe7d6a commit 5b9acbe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
if (!Line->InMacroBody && !Style.isTableGen()) {
// Skip PPDirective lines and comments.
while (NextTok->is(tok::hash)) {
NextTok = Tokens->getNextToken();
if (NextTok->is(tok::pp_not_keyword))
break;
do {
NextTok = Tokens->getNextToken();
} while (NextTok->NewlinesBefore == 0 && NextTok->isNot(tok::eof));
Expand Down
11 changes: 11 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3216,6 +3216,17 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
EXPECT_BRACE_KIND(Tokens[17], BK_Block);
EXPECT_BRACE_KIND(Tokens[22], BK_Block);
EXPECT_BRACE_KIND(Tokens[26], BK_Block);

Tokens = annotate("{\n"
"#define M(x) \\\n"
" return {#x};\n"
"}");
ASSERT_EQ(Tokens.size(), 15u) << Tokens;
EXPECT_TOKEN(Tokens[0], tok::l_brace, TT_BlockLBrace);
EXPECT_BRACE_KIND(Tokens[0], BK_Block);
EXPECT_BRACE_KIND(Tokens[8], BK_BracedInit);
EXPECT_BRACE_KIND(Tokens[11], BK_BracedInit);
EXPECT_BRACE_KIND(Tokens[13], BK_Block);
}

TEST_F(TokenAnnotatorTest, UnderstandsElaboratedTypeSpecifier) {
Expand Down

0 comments on commit 5b9acbe

Please sign in to comment.