Skip to content

Commit d15c79f

Browse files
committed
Allow array alignment to happen on non-rectangular arrays
1 parent d87eea3 commit d15c79f

File tree

4 files changed

+320
-215
lines changed

4 files changed

+320
-215
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4251,7 +4251,28 @@ FormatToken *TokenAnnotator::calculateInitializerColumnList(
42514251
CurrentToken = CurrentToken->Next;
42524252
if (!CurrentToken)
42534253
break;
4254-
CurrentToken->StartsColumn = true;
4254+
4255+
// Right (closing) braces should not count as starting a column because
4256+
// they are aligned using separate logic.
4257+
4258+
// Note: This uses startsSequence() so that trailing comments are skipped
4259+
// when checking if the token after a comma/l-brace is a r_brace. We can't
4260+
// just ignore comments in general, because an inline comment with
4261+
// something else after it should still count as starting a column.
4262+
// IE:
4263+
//
4264+
// { // a
4265+
// 4
4266+
// }
4267+
//
4268+
// vs.
4269+
//
4270+
// { /* a */ 4 }
4271+
//
4272+
// In the first case, the comment does not start a column, but in the
4273+
// second it does
4274+
CurrentToken->StartsColumn = !CurrentToken->startsSequence(tok::r_brace);
4275+
42554276
CurrentToken = CurrentToken->Previous;
42564277
}
42574278
CurrentToken = CurrentToken->Next;

0 commit comments

Comments
 (0)