]> granicus.if.org Git - clang/commitdiff
clang-format: Don't break after very short return types.
authorDaniel Jasper <djasper@google.com>
Mon, 27 Oct 2014 17:13:59 +0000 (17:13 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 27 Oct 2014 17:13:59 +0000 (17:13 +0000)
Before:
  void
  SomeFunction(int parameter);

After:
  void SomeFunction(
      int parameter);

(Unless AlwaysBreakAfterDefinitionReturnType after type is set).

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

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

index 82dffd6fff582e7f78a988bf39b5397042e50bd8..a6fb40ece7a9ea9afbdde49f037c49469ffa267b 100644 (file)
@@ -122,6 +122,12 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
       State.Stack[State.Stack.size() - 2].HasMultipleNestedBlocks)
     return false;
 
+  // Don't break after very short return types (e.g. "void") as that is often
+  // unexpected.
+  if (Current.Type == TT_FunctionDeclarationName &&
+      !Style.AlwaysBreakAfterDefinitionReturnType && State.Column < 6)
+    return false;
+
   return !State.Stack.back().NoLineBreak;
 }
 
index f29aff8f0e94e5ad5b3098d08b435b8b075d259a..56163f70070f9cb3128eb87515d082e061f0d5c1 100644 (file)
@@ -1207,8 +1207,8 @@ TEST_F(FormatTest, CorrectlyHandlesLengthOfBlockComments) {
 }
 
 TEST_F(FormatTest, DontBreakNonTrailingBlockComments) {
-  EXPECT_EQ("void\n"
-            "ffffffffff(int aaaaa /* test */);",
+  EXPECT_EQ("void ffffffffff(\n"
+            "    int aaaaa /* test */);",
             format("void ffffffffff(int aaaaa /* test */);",
                    getLLVMStyleWithColumns(35)));
 }
@@ -1258,11 +1258,11 @@ TEST_F(FormatTest, SplitsLongCxxComments) {
             format("// A comment before a macro definition\n"
                    "#define a b",
                    getLLVMStyleWithColumns(20)));
-  EXPECT_EQ("void\n"
-            "ffffff(int aaaaaaaaa,  // wwww\n"
-            "       int bbbbbbbbbb, // xxxxxxx\n"
-            "                       // yyyyyyyyyy\n"
-            "       int c, int d, int e) {}",
+  EXPECT_EQ("void ffffff(\n"
+            "    int aaaaaaaaa,  // wwww\n"
+            "    int bbbbbbbbbb, // xxxxxxx\n"
+            "                    // yyyyyyyyyy\n"
+            "    int c, int d, int e) {}",
             format("void ffffff(\n"
                    "    int aaaaaaaaa, // wwww\n"
                    "    int bbbbbbbbbb, // xxxxxxx yyyyyyyyyy\n"
@@ -3538,8 +3538,8 @@ TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {
   // they are not function-like.
   FormatStyle Style = getGoogleStyle();
   Style.ColumnLimit = 47;
-  verifyFormat("void\n"
-               "someLongFunction(int someLongParameter) const {\n}",
+  verifyFormat("void someLongFunction(\n"
+               "    int someLoooooooooooooongParameter) const {\n}",
                getLLVMStyleWithColumns(47));
   verifyFormat("LoooooongReturnType\n"
                "someLoooooooongFunction() const {}",
@@ -7400,7 +7400,7 @@ TEST_F(FormatTest, ConfigurableIndentWidth) {
 }
 
 TEST_F(FormatTest, ConfigurableFunctionDeclarationIndentAfterType) {
-  verifyFormat("void\n"
+  verifyFormat("double\n"
                "f();",
                getLLVMStyleWithColumns(8));
 }