Skip to content

Commit 3f82d66

Browse files
committed
Fix real problem
1 parent 78e006d commit 3f82d66

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,8 +1455,11 @@ WhitespaceManager::CellDescriptions WhitespaceManager::getCells(unsigned Start,
14551455
if (!Cells.empty())
14561456
Cells.back().EndIndex = i;
14571457
Cells.push_back(CellDescription{i, ++Cell, i + 1, false, nullptr});
1458-
CellCounts.push_back(C.Tok->Previous->isNot(tok::comma) ? Cell + 1
1459-
: Cell);
1458+
CellCounts.push_back(
1459+
C.Tok->Previous->isNot(tok::comma) &&
1460+
!MatchingParen->MatchingParen->Previous->is(tok::equal)
1461+
? Cell + 1
1462+
: Cell);
14601463
// Go to the next non-comment and ensure there is a break in front
14611464
const auto *NextNonComment = C.Tok->getNextNonComment();
14621465
while (NextNonComment->is(tok::comma))

clang/unittests/Format/FormatTest.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20847,6 +20847,11 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) {
2084720847
" [1] { 1, },\n"
2084820848
"};",
2084920849
Style);
20850+
verifyNoCrash("Foo foo[] = {\n"
20851+
" [0] = {1, 1},\n"
20852+
" [1] { 1, 1, },\n"
20853+
" [2] { 1, 1, },\n"
20854+
"};");
2085020855

2085120856
verifyFormat("return GradForUnaryCwise(g, {\n"
2085220857
" {{\"sign\"}, \"Sign\", "
@@ -21095,6 +21100,11 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresLeftAlignment) {
2109521100
" [1] { 1, },\n"
2109621101
"};",
2109721102
Style);
21103+
verifyNoCrash("Foo foo[] = {\n"
21104+
" [0] = {1, 1},\n"
21105+
" [1] { 1, 1, },\n"
21106+
" [2] { 1, 1, },\n"
21107+
"};");
2109821108

2109921109
verifyFormat("return GradForUnaryCwise(g, {\n"
2110021110
" {{\"sign\"}, \"Sign\", {\"x\", "

0 commit comments

Comments
 (0)