]> granicus.if.org Git - clang/commitdiff
Fix crash on invalid.
authorManuel Klimek <klimek@google.com>
Fri, 11 Jan 2013 18:28:36 +0000 (18:28 +0000)
committerManuel Klimek <klimek@google.com>
Fri, 11 Jan 2013 18:28:36 +0000 (18:28 +0000)
if { foo; }
would previously crash clang-format.

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

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

index 758f8193ca4f720d4a9f105417d95cff3209b12a..07ad7a7489e02b26515bfcdccfa7c10d0c942d7f 100644 (file)
@@ -404,7 +404,8 @@ void UnwrappedLineParser::parseParens() {
 void UnwrappedLineParser::parseIfThenElse() {
   assert(FormatTok.Tok.is(tok::kw_if) && "'if' expected");
   nextToken();
-  parseParens();
+  if (FormatTok.Tok.is(tok::l_paren))
+    parseParens();
   bool NeedsUnwrappedLine = false;
   if (FormatTok.Tok.is(tok::l_brace)) {
     parseBlock();
index 71fa83ccb1405486488fedf9a62bb8e3820c2a51..6beee3186b723cdd3261f066d6bffabea29b91af 100644 (file)
@@ -1108,6 +1108,10 @@ TEST_F(FormatTest, IncorrectCodeDoNoWhile) {
                "}");
 }
 
+TEST_F(FormatTest, IncorrectIf) {
+  verifyFormat("if {\n  foo;\n  foo();\n}");
+}
+
 TEST_F(FormatTest, DoesNotTouchUnwrappedLinesWithErrors) {
   verifyFormat("namespace {\n"
                "class Foo {  Foo  ( }; }  // comment");