Skip to content

Commit ac771f4

Browse files
authored
[clang-format] Fix a bug in SkipMacroDefinitionBody (llvm#155346)
All comments before the macro definition body should be skipped.
1 parent 8cf2d27 commit ac771f4

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,11 +1207,8 @@ void UnwrappedLineParser::parsePPDefine() {
12071207
return;
12081208
}
12091209

1210-
if (auto *Prev = Tokens->getPreviousToken(); Prev->is(tok::comment) &&
1211-
Prev->NewlinesBefore > 0 &&
1212-
!Prev->HasUnescapedNewline) {
1213-
Prev->Finalized = true;
1214-
}
1210+
for (auto *Comment : CommentsBeforeNextToken)
1211+
Comment->Finalized = true;
12151212

12161213
do {
12171214
FormatTok->Finalized = true;

clang/unittests/Format/FormatTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25661,6 +25661,7 @@ TEST_F(FormatTest, SkipMacroDefinitionBody) {
2566125661
" A a",
2566225662
Style);
2566325663
verifyNoChange("#define MY_MACRO \\\n"
25664+
" /*foo*//*bar*/ \\\n"
2566425665
" /* comment */ \\\n"
2566525666
" 1",
2566625667
Style);

0 commit comments

Comments
 (0)