Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1182,34 +1182,43 @@ void UnwrappedLineParser::parsePPDefine() {
if (MaybeIncludeGuard && !eof())
IncludeGuard = IG_Rejected;

if (FormatTok->Tok.getKind() == tok::l_paren &&
!FormatTok->hasWhitespaceBefore()) {
if (FormatTok->is(tok::l_paren) && !FormatTok->hasWhitespaceBefore())
parseParens();
}
if (Style.IndentPPDirectives != FormatStyle::PPDIS_None)
Line->Level += PPBranchLevel + 1;
addUnwrappedLine();
++Line->Level;

Line->PPLevel = PPBranchLevel + (IncludeGuard == IG_Defined ? 0 : 1);
assert((int)Line->PPLevel >= 0);

if (eof())
return;

Line->InMacroBody = true;

if (Style.SkipMacroDefinitionBody) {
while (!eof()) {
FormatTok->Finalized = true;
FormatTok = Tokens->getNextToken();
}
addUnwrappedLine();
if (!Style.SkipMacroDefinitionBody) {
// Errors during a preprocessor directive can only affect the layout of the
// preprocessor directive, and thus we ignore them. An alternative approach
// would be to use the same approach we use on the file level (no
// re-indentation if there was a structural error) within the macro
// definition.
parseFile();
return;
}

// Errors during a preprocessor directive can only affect the layout of the
// preprocessor directive, and thus we ignore them. An alternative approach
// would be to use the same approach we use on the file level (no
// re-indentation if there was a structural error) within the macro
// definition.
parseFile();
if (auto *Prev = Tokens->getPreviousToken(); Prev->is(tok::comment) &&
Prev->NewlinesBefore > 0 &&
!Prev->HasUnescapedNewline) {
Prev->Finalized = true;
}

do {
FormatTok->Finalized = true;
FormatTok = Tokens->getNextToken();
} while (!eof());

addUnwrappedLine();
}

void UnwrappedLineParser::parsePPPragma() {
Expand Down
4 changes: 4 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26022,6 +26022,10 @@ TEST_F(FormatTest, SkipMacroDefinitionBody) {
" A a \\\n "
" A a",
Style);
verifyNoChange("#define MY_MACRO \\\n"
" /* comment */ \\\n"
" 1",
Style);
}

TEST_F(FormatTest, VeryLongNamespaceCommentSplit) {
Expand Down