Skip to content

[clang-format] Allow array alignment on non-rectangular arrays #143781

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
23 changes: 22 additions & 1 deletion clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4251,7 +4251,28 @@ FormatToken *TokenAnnotator::calculateInitializerColumnList(
CurrentToken = CurrentToken->Next;
if (!CurrentToken)
break;
CurrentToken->StartsColumn = true;

// Right (closing) braces should not count as starting a column because
// they are aligned using separate logic.

// Note: This uses startsSequence() so that trailing comments are skipped
// when checking if the token after a comma/l-brace is a r_brace. We can't
// just ignore comments in general, because an inline comment with
// something else after it should still count as starting a column.
// IE:
//
// { // a
// 4
// }
//
// vs.
//
// { /* a */ 4 }
//
// In the first case, the comment does not start a column, but in the
// second it does.
CurrentToken->StartsColumn = !CurrentToken->startsSequence(tok::r_brace);

CurrentToken = CurrentToken->Previous;
}
CurrentToken = CurrentToken->Next;
Expand Down
Loading