]> granicus.if.org Git - clang/commitdiff
Get less confused by trailing comma in Google style.
authorDaniel Jasper <djasper@google.com>
Thu, 14 Feb 2013 09:19:04 +0000 (09:19 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 14 Feb 2013 09:19:04 +0000 (09:19 +0000)
The formatter can now format:
void aaaaaaaaaaaaaaaaaa(int level,
                        double *min_x,
                        double *max_x,
                        double *min_y,
                        double *max_y,
                        double *min_z,
                        double *max_z, ) {
}

Although this is invalid code, it frequently happens during development and
clang-format should be nicer :-).

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

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

index 1bd864e5c9d7e1aa57fa2082e30e6baed38ec945..f03b77853ce97e35324acc41d24854fac94975c1 100644 (file)
@@ -781,7 +781,8 @@ private:
       return true;
     if (State.NextToken->Parent->is(tok::comma) &&
         State.Stack.back().BreakBeforeParameter &&
-        !isTrailingComment(*State.NextToken))
+        !isTrailingComment(*State.NextToken) &&
+        State.NextToken->isNot(tok::r_paren))
       return true;
     // FIXME: Comparing LongestObjCSelectorName to 0 is a hacky way of finding
     // out whether it is the first parameter. Clean this up.
index d5e3c24545a36b68cdee75f8977e57cd56dba77d..e99aad7a8cf38066c17a14887c81c49d8c692e52 100644 (file)
@@ -1817,6 +1817,17 @@ TEST_F(FormatTest, HandlesIncludeDirectives) {
 // Error recovery tests.
 //===----------------------------------------------------------------------===//
 
+TEST_F(FormatTest, IncompleteParameterLists) {
+  verifyGoogleFormat("void aaaaaaaaaaaaaaaaaa(int level,\n"
+                     "                        double *min_x,\n"
+                     "                        double *max_x,\n"
+                     "                        double *min_y,\n"
+                     "                        double *max_y,\n"
+                     "                        double *min_z,\n"
+                     "                        double *max_z, ) {\n"
+                     "}");
+}
+
 TEST_F(FormatTest, IncorrectCodeTrailingStuff) {
   verifyFormat("void f() { return; }\n42");
   verifyFormat("void f() {\n"