]> granicus.if.org Git - clang/commitdiff
Clang Format: Handle missing semicolon
authorAlexander Kornienko <alexfh@google.com>
Wed, 16 Jan 2013 11:43:46 +0000 (11:43 +0000)
committerAlexander Kornienko <alexfh@google.com>
Wed, 16 Jan 2013 11:43:46 +0000 (11:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172606 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 9a29ff011ae17ff76c99c36a6a06d5b4e5254845..d6c66dc9ac452c92af70cd407effe407857cf847 100644 (file)
@@ -306,8 +306,8 @@ void UnwrappedLineParser::parseStructuralElement() {
     case tok::kw_enum:
       parseEnum();
       return;
-    case tok::kw_struct: // fallthrough
-    case tok::kw_union:  // fallthrough
+    case tok::kw_struct:
+    case tok::kw_union:
     case tok::kw_class:
       parseRecord();
       // A record declaration or definition is always the start of a structural
@@ -317,6 +317,9 @@ void UnwrappedLineParser::parseStructuralElement() {
       nextToken();
       addUnwrappedLine();
       return;
+    case tok::r_brace:
+      addUnwrappedLine();
+      return;
     case tok::l_paren:
       parseParens();
       break;
index ca022a4bbe806810ccd58d5132ebcfc16ed245d9..4d860c1f65619e2994c0a381ab7c281a3c750555 100644 (file)
@@ -1213,7 +1213,25 @@ TEST_F(FormatTest, HandlesIncludeDirectives) {
 //===----------------------------------------------------------------------===//
 
 TEST_F(FormatTest, IncorrectCodeTrailingStuff) {
-  verifyFormat("void f() {  return } 42");
+  verifyFormat("void f() { return }\n42");
+  verifyFormat("void f() {\n"
+               "  if (0)\n"
+               "    return\n"
+               "}\n"
+               "42");
+}
+
+TEST_F(FormatTest, IncorrectCodeMissingSemicolon) {
+  EXPECT_EQ("void f() { return }", format("void  f ( )  {  return  }"));
+  EXPECT_EQ("void f() {\n"
+            "  if (a)\n"
+            "    return\n"
+            "}", format("void  f  (  )  {  if  ( a )  return  }"));
+  EXPECT_EQ("namespace N { void f() }", format("namespace  N  {  void f()  }"));
+  EXPECT_EQ("namespace N {\n"
+            "void f() {}\n"
+            "void g()\n"
+            "}", format("namespace N  { void f( ) { } void g( ) }"));
 }
 
 TEST_F(FormatTest, IndentationWithinColumnLimitNotPossible) {