r192984 - clang-format: Don't force linebreak between return and multiline string.

Daniel Jasper djasper at google.com
Fri Oct 18 09:47:56 PDT 2013


Author: djasper
Date: Fri Oct 18 11:47:55 2013
New Revision: 192984

URL: http://llvm.org/viewvc/llvm-project?rev=192984&view=rev
Log:
clang-format: Don't force linebreak between return and multiline string.

This looks ugly and leads to llvm.org/PR17590.

Before (with AlwaysBreakBeforeMultilineStrings):
  return
      "aaaa"
      "bbbb";

After:
  return "aaaa"
         "bbbb";

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

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=192984&r1=192983&r2=192984&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Oct 18 11:47:55 2013
@@ -133,8 +133,8 @@ bool ContinuationIndenter::mustBreak(con
     return true;
   if (Style.AlwaysBreakBeforeMultilineStrings &&
       State.Column > State.Stack.back().Indent && // Breaking saves columns.
-      Previous.isNot(tok::lessless) && Previous.Type != TT_InlineASMColon &&
-      NextIsMultilineString(State))
+      !Previous.isOneOf(tok::kw_return, tok::lessless) &&
+      Previous.Type != TT_InlineASMColon && NextIsMultilineString(State))
     return true;
 
   if (!Style.BreakBeforeBinaryOperators) {

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=192984&r1=192983&r2=192984&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Oct 18 11:47:55 2013
@@ -5590,6 +5590,12 @@ TEST_F(FormatTest, BreakStringLiterals)
                    "aaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa "
                    "aaaaaaaaaaaaaaaaaaaaaa\");",
                    getGoogleStyle()));
+  EXPECT_EQ("return \"aaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaa \"\n"
+            "       \"aaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa\";",
+            format("return \"aaaaaaaaaaaaaaaaaaaaaa "
+                   "aaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaa "
+                   "aaaaaaaaaaaaaaaaaaaaaa\";",
+                   getGoogleStyle()));
   EXPECT_EQ("llvm::outs() << \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \"\n"
             "                \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\";",
             format("llvm::outs() << "





More information about the cfe-commits mailing list