From: Daniel Jasper Date: Tue, 12 Feb 2013 20:17:17 +0000 (+0000) Subject: Fix crash for incomplete labels in macros. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f52ab8d60cfc3222b7b7543c8789e1c507b1b438;p=platform%2Fupstream%2Fllvm.git Fix crash for incomplete labels in macros. Still the formatting can be improved, but at least we don't assert any more. This happened when trying to format lib/Sema/SemaType.cpp. llvm-svn: 175003 --- diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 9226716..28522a3 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -565,8 +565,8 @@ void UnwrappedLineParser::parseDoWhile() { } void UnwrappedLineParser::parseLabel() { - // FIXME: remove all asserts. - assert(FormatTok.Tok.is(tok::colon) && "':' expected"); + if (FormatTok.Tok.isNot(tok::colon)) + return; nextToken(); unsigned OldLineLevel = Line->Level; if (Line->Level > 0) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index f1cef2a..f28bc88 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -353,6 +353,12 @@ TEST_F(FormatTest, FormatsSwitchStatement) { "}"); verifyFormat("switch (test)\n" " ;"); + + // FIXME: Improve formatting of case labels in macros. + verifyFormat("#define SOMECASES \\\n" + "case 1: \\\n" + " case 2\n", getLLVMStyleWithColumns(20)); + verifyGoogleFormat("switch (x) {\n" " case 1:\n" " f();\n"