Skip to content

[clang-format] Fix a bug in ContinuationIndenter #78921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2024
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
3 changes: 2 additions & 1 deletion clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,8 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,

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

// If "BreakBeforeInheritanceComma" mode, don't break within the inheritance
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Format/WhitespaceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class WhitespaceManager {
/// this replacement. It is needed for determining how \p Spaces is turned
/// into tabs and spaces for some format styles.
void replaceWhitespace(FormatToken &Tok, unsigned Newlines, unsigned Spaces,
unsigned StartOfTokenColumn, bool isAligned = false,
unsigned StartOfTokenColumn, bool IsAligned = false,
bool InPPDirective = false);

/// Adds information about an unchangeable token's whitespace.
Expand Down
7 changes: 7 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21203,6 +21203,13 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresLeftAlignment) {
"});",
Style);

Style.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign;
verifyFormat("#define FOO \\\n"
" int foo[][2] = { \\\n"
" {0, 1} \\\n"
" };",
Style);

Style.Cpp11BracedListStyle = false;
verifyFormat("struct test demo[] = {\n"
" { 56, 23, \"hello\" },\n"
Expand Down