[cfe-commits] r172606 - in /cfe/trunk: lib/Format/UnwrappedLineParser.cpp unittests/Format/FormatTest.cpp

Alexander Kornienko alexfh at google.com
Wed Jan 16 03:43:46 PST 2013


Author: alexfh
Date: Wed Jan 16 05:43:46 2013
New Revision: 172606

URL: http://llvm.org/viewvc/llvm-project?rev=172606&view=rev
Log:
Clang Format: Handle missing semicolon

Modified:
    cfe/trunk/lib/Format/UnwrappedLineParser.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=172606&r1=172605&r2=172606&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Jan 16 05:43:46 2013
@@ -306,8 +306,8 @@
     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 @@
       nextToken();
       addUnwrappedLine();
       return;
+    case tok::r_brace:
+      addUnwrappedLine();
+      return;
     case tok::l_paren:
       parseParens();
       break;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172606&r1=172605&r2=172606&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jan 16 05:43:46 2013
@@ -1213,7 +1213,25 @@
 //===----------------------------------------------------------------------===//
 
 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) {





More information about the cfe-commits mailing list