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
11 changes: 7 additions & 4 deletions clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,9 +798,11 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
}

if (!DryRun) {
const bool ContinuePPDirective =
State.Line->InMacroBody && Current.isNot(TT_LineComment);
Whitespaces.replaceWhitespace(Current, /*Newlines=*/0, Spaces,
State.Column + Spaces + PPColumnCorrection,
/*IsAligned=*/false, State.Line->InMacroBody);
/*IsAligned=*/false, ContinuePPDirective);
}

// If "BreakBeforeInheritanceComma" mode, don't break within the inheritance
Expand Down Expand Up @@ -1176,10 +1178,11 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
// about removing empty lines on closing blocks. Special case them here.
MaxEmptyLinesToKeep = 1;
}
unsigned Newlines =
const unsigned Newlines =
std::max(1u, std::min(Current.NewlinesBefore, MaxEmptyLinesToKeep));
bool ContinuePPDirective =
State.Line->InPPDirective && State.Line->Type != LT_ImportStatement;
const bool ContinuePPDirective = State.Line->InPPDirective &&
State.Line->Type != LT_ImportStatement &&
Current.isNot(TT_LineComment);
Whitespaces.replaceWhitespace(Current, Newlines, State.Column, State.Column,
CurrentState.IsAligned, ContinuePPDirective);
}
Expand Down
19 changes: 19 additions & 0 deletions clang/unittests/Format/FormatTestComments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,25 @@ TEST_F(FormatTestComments, MultiLineCommentsInDefines) {
getLLVMStyleWithColumns(17)));
}

TEST_F(FormatTestComments, LineCommentsInMacrosDoNotGetEscapedNewlines) {
FormatStyle Style = getLLVMStyleWithColumns(0);
Style.ReflowComments = FormatStyle::RCS_Never;
verifyFormat("#define FOO (1U) // comment\n"
" // comment",
Style);

Style.ColumnLimit = 32;
verifyFormat("#define SOME_MACRO(x) x\n"
"#define FOO \\\n"
" SOME_MACRO(1) + \\\n"
" SOME_MACRO(2) // comment\n"
" // comment",
"#define SOME_MACRO(x) x\n"
"#define FOO SOME_MACRO(1) + SOME_MACRO(2) // comment\n"
" // comment",
Style);
}

TEST_F(FormatTestComments, ParsesCommentsAdjacentToPPDirectives) {
EXPECT_EQ("namespace {}\n// Test\n#define A",
format("namespace {}\n // Test\n#define A"));
Expand Down
Loading