diff options
-rw-r--r-- | clang/lib/Format/WhitespaceManager.cpp | 4 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 10 |
2 files changed, 13 insertions, 1 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index f1d176f..8415c8d 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -1451,8 +1451,10 @@ WhitespaceManager::CellDescriptions WhitespaceManager::getCells(unsigned Start, } else if (C.Tok->is(tok::comma)) { if (!Cells.empty()) Cells.back().EndIndex = i; - if (C.Tok->getNextNonComment()->isNot(tok::r_brace)) // dangling comma + if (const auto *Next = C.Tok->getNextNonComment(); + Next && Next->isNot(tok::r_brace)) { // dangling comma ++Cell; + } } } else if (Depth == 1) { if (C.Tok == MatchingParen) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 8f115fb..340ae39 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -20931,6 +20931,11 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) { "};", Style); + verifyNoCrash("Foo f[] = {\n" + " [0] = { 1, },\n" + " [i] { 1, },\n" + "};", + Style); verifyNoCrash("Foo foo[] = {\n" " [0] = {1, 1},\n" " [1] { 1, 1, },\n" @@ -21179,6 +21184,11 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresLeftAlignment) { "};", Style); + verifyNoCrash("Foo f[] = {\n" + " [0] = { 1, },\n" + " [i] { 1, },\n" + "};", + Style); verifyNoCrash("Foo foo[] = {\n" " [0] = {1, 1},\n" " [1] { 1, 1, },\n" |