Skip to content

Commit d40e09f

Browse files
committed
Fix root cause
1 parent 59a6ea0 commit d40e09f

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,6 +2315,10 @@ bool UnwrappedLineParser::tryToParseLambdaIntroducer() {
23152315
if (Next->is(tok::greater))
23162316
return false;
23172317
}
2318+
if (const auto Kind = FormatTok->Tok.getKind();
2319+
tok::isLiteral(Kind) && !tok::isStringLiteral(Kind)) {
2320+
return false;
2321+
}
23182322
parseSquare(/*LambdaIntroducer=*/true);
23192323
return true;
23202324
}

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,15 +1455,8 @@ 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(
1459-
C.Tok->Previous->isNot(tok::comma) &&
1460-
// When dealing with C array designators. There is a
1461-
// possibility of some nested array not having an `=`.
1462-
// When this happens we make the cells non retangular,
1463-
// avoiding an access out of bound later on.
1464-
MatchingParen->MatchingParen->Previous->isNot(tok::equal)
1465-
? Cell + 1
1466-
: Cell);
1458+
CellCounts.push_back(C.Tok->Previous->isNot(tok::comma) ? Cell + 1
1459+
: Cell);
14671460
// Go to the next non-comment and ensure there is a break in front
14681461
const auto *NextNonComment = C.Tok->getNextNonComment();
14691462
while (NextNonComment->is(tok::comma))

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,6 +2324,11 @@ TEST_F(TokenAnnotatorTest, UnderstandDesignatedInitializers) {
23242324
EXPECT_BRACE_KIND(Tokens[1], BK_BracedInit);
23252325
EXPECT_TOKEN(Tokens[6], tok::period, TT_DesignatedInitializerPeriod);
23262326
EXPECT_TOKEN(Tokens[13], tok::period, TT_DesignatedInitializerPeriod);
2327+
2328+
Tokens = annotate("Foo foo[] = {[0]{}};");
2329+
ASSERT_EQ(Tokens.size(), 14u) << Tokens;
2330+
EXPECT_TOKEN(Tokens[6], tok::l_square, TT_DesignatedInitializerLSquare);
2331+
EXPECT_BRACE_KIND(Tokens[9], BK_BracedInit);
23272332
}
23282333

23292334
TEST_F(TokenAnnotatorTest, UnderstandsJavaScript) {

0 commit comments

Comments
 (0)