Skip to content

Commit 04dab5e

Browse files
committed
[clang-format] Fix a bug in SkipMacroDefinitionBody
Fixes #154683
1 parent 6cfedea commit 04dab5e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,10 +1182,8 @@ void UnwrappedLineParser::parsePPDefine() {
11821182
if (MaybeIncludeGuard && !eof())
11831183
IncludeGuard = IG_Rejected;
11841184

1185-
if (FormatTok->Tok.getKind() == tok::l_paren &&
1186-
!FormatTok->hasWhitespaceBefore()) {
1185+
if (FormatTok->is(tok::l_paren) && !FormatTok->hasWhitespaceBefore())
11871186
parseParens();
1188-
}
11891187
if (Style.IndentPPDirectives != FormatStyle::PPDIS_None)
11901188
Line->Level += PPBranchLevel + 1;
11911189
addUnwrappedLine();
@@ -1196,6 +1194,11 @@ void UnwrappedLineParser::parsePPDefine() {
11961194
Line->InMacroBody = true;
11971195

11981196
if (Style.SkipMacroDefinitionBody) {
1197+
if (auto *Prev = Tokens->getPreviousToken(); Prev->is(tok::comment) &&
1198+
Prev->NewlinesBefore > 0 &&
1199+
!Prev->HasUnescapedNewline) {
1200+
Prev->Finalized = true;
1201+
}
11991202
while (!eof()) {
12001203
FormatTok->Finalized = true;
12011204
FormatTok = Tokens->getNextToken();

clang/unittests/Format/FormatTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26022,6 +26022,10 @@ TEST_F(FormatTest, SkipMacroDefinitionBody) {
2602226022
" A a \\\n "
2602326023
" A a",
2602426024
Style);
26025+
verifyNoChange("#define MY_MACRO \\\n"
26026+
" /* this is a comment */ \\\n"
26027+
" 1",
26028+
Style);
2602526029
}
2602626030

2602726031
TEST_F(FormatTest, VeryLongNamespaceCommentSplit) {

0 commit comments

Comments
 (0)