]> granicus.if.org Git - clang/commitdiff
Fix crash for incomplete labels in macros.
authorDaniel Jasper <djasper@google.com>
Tue, 12 Feb 2013 20:17:17 +0000 (20:17 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 12 Feb 2013 20:17:17 +0000 (20:17 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175003 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp

index 922671600d2e0d48e6d69ae2e0f3eaebc1f88d98..28522a3e32708776bc1d09306112e32f2b6ff330 100644 (file)
@@ -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)
index f1cef2a03d13f2010cfd38884a92f979d9caff60..f28bc884445f0e45c970f4f384b8abb271e252b5 100644 (file)
@@ -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"