]> granicus.if.org Git - clang/commitdiff
Clang-format error recovery part 1
authorAlexander Kornienko <alexfh@google.com>
Tue, 4 Dec 2012 15:40:36 +0000 (15:40 +0000)
committerAlexander Kornienko <alexfh@google.com>
Tue, 4 Dec 2012 15:40:36 +0000 (15:40 +0000)
Reviewers: klimek

CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D163

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

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

index 7c04ce09dda936c6c4a2e34138a4a12b01cd6d97..888f1c9eeb99621ac194178dc6da88e11aa0e5cd 100644 (file)
@@ -72,7 +72,10 @@ void UnwrappedLineParser::parseBlock() {
   parseLevel();
   if (!IsNamespace)
     --Line.Level;
-  assert(FormatTok.Tok.is(tok::r_brace) && "expected '}'");
+  // FIXME: Add error handling.
+  if (!FormatTok.Tok.is(tok::r_brace))
+    return;
+
   nextToken();
   if (FormatTok.Tok.is(tok::semi))
     nextToken();
@@ -218,7 +221,12 @@ void UnwrappedLineParser::parseDoWhile() {
     --Line.Level;
   }
 
-  assert(FormatTok.Tok.is(tok::kw_while) && "'while' expected");
+  // FIXME: Add error handling.
+  if (!FormatTok.Tok.is(tok::kw_while)) {
+    addUnwrappedLine();
+    return;
+  }
+
   nextToken();
   parseStatement();
 }
index e21367bb315db3e264491ec9c877a6a93a74513e..5c1b6031c6decb7d364a8b3ae79135da2d0b8120 100644 (file)
@@ -363,5 +363,23 @@ TEST_F(FormatTest, HandlesIncludeDirectives) {
 //               "};");
 //}
 
+TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) {
+  verifyFormat("{");
+}
+
+TEST_F(FormatTest, IncorrectCodeDoNoWhile) {
+  verifyFormat("do {\n"
+               "};");
+  verifyFormat("do {\n"
+               "};\n"
+               "f();");
+  verifyFormat("do {\n"
+               "}\n"
+               "wheeee(fun);");
+  verifyFormat("do {\n"
+               "  f();\n"
+               "};");
+}
+
 }  // end namespace tooling
 }  // end namespace clang