Skip to content

Commit eb7235c

Browse files
committed
[clang-format] Fix a bug in SkipMacroDefinitionBody
All comments before the macro definition body should be skipped.
1 parent 0b1d353 commit eb7235c

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
@@ -26023,6 +26023,7 @@ TEST_F(FormatTest, SkipMacroDefinitionBody) {
2602326023
" A a",
2602426024
Style);
2602526025
verifyNoChange("#define MY_MACRO \\\n"
26026+
" /*foo*//*bar*/ \\\n"
2602626027
" /* comment */ \\\n"
2602726028
" 1",
2602826029
Style);

0 commit comments

Comments
 (0)