r194310 - clang-format: Fix alignment of ObjC string literals.

Daniel Jasper djasper at google.com
Fri Nov 8 19:08:26 PST 2013


Author: djasper
Date: Fri Nov  8 21:08:25 2013
New Revision: 194310

URL: http://llvm.org/viewvc/llvm-project?rev=194310&view=rev
Log:
clang-format: Fix alignment of ObjC string literals.

This used to interfere with AlwaysBreakBeforeMultilineStrings.

This fixes llvm.org/PR17856.

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=194310&r1=194309&r2=194310&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Nov  8 21:08:25 2013
@@ -135,7 +135,7 @@ bool ContinuationIndenter::mustBreak(con
     return true;
   if (Style.AlwaysBreakBeforeMultilineStrings &&
       State.Column > State.Stack.back().Indent && // Breaking saves columns.
-      !Previous.isOneOf(tok::kw_return, tok::lessless) &&
+      !Previous.isOneOf(tok::kw_return, tok::lessless, tok::at) &&
       Previous.Type != TT_InlineASMColon && NextIsMultilineString(State))
     return true;
   if (((Previous.Type == TT_DictLiteral && Previous.is(tok::l_brace)) ||

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=194310&r1=194309&r2=194310&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Nov  8 21:08:25 2013
@@ -3636,6 +3636,13 @@ TEST_F(FormatTest, AlwaysBreakBeforeMult
                    "b\\\n"
                    "c\";",
                    Break));
+
+  // Exempt ObjC strings for now.
+  EXPECT_EQ("NSString *const kString = @\"aaaa\"\n"
+            "                           \"bbbb\";",
+            format("NSString *const kString = @\"aaaa\"\n"
+                   "\"bbbb\";",
+                   Break));
 }
 
 TEST_F(FormatTest, AlignsPipes) {





More information about the cfe-commits mailing list