]> granicus.if.org Git - clang/commitdiff
clang-format: Fix bug introduced in r198871.
authorDaniel Jasper <djasper@google.com>
Tue, 14 Jan 2014 09:53:07 +0000 (09:53 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 14 Jan 2014 09:53:07 +0000 (09:53 +0000)
We cannot simply change the start column to accomodate for the @ in an
ObjC string literal as that will make clang-format happily violate the
column limit.

Use a different workaround instead. However, a better long-term
solution might be to join the @ and the rest of the literal into a
single token.

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

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

index 8ca97d37a274d17a027a5da39f338a2beeef0655..03693c62bb41a15cd91572be05084d48194bfa55 100644 (file)
@@ -172,9 +172,16 @@ BreakableStringLiteral::getSplit(unsigned LineIndex, unsigned TailOffset,
 void BreakableStringLiteral::insertBreak(unsigned LineIndex,
                                          unsigned TailOffset, Split Split,
                                          WhitespaceManager &Whitespaces) {
+  unsigned LeadingSpaces = StartColumn;
+  // The '@' of an ObjC string literal (@"Test") does not become part of the
+  // string token.
+  // FIXME: It might be a cleaner solution to merge the tokens as a
+  // precomputation step.
+  if (Prefix.startswith("@"))
+    --LeadingSpaces;
   Whitespaces.replaceWhitespaceInToken(
       Tok, Prefix.size() + TailOffset + Split.first, Split.second, Postfix,
-      Prefix, InPPDirective, 1, IndentLevel, StartColumn);
+      Prefix, InPPDirective, 1, IndentLevel, LeadingSpaces);
 }
 
 static StringRef getLineCommentPrefix(StringRef Comment) {
index aaedceb31e81d969d9d57aacb51dd890132a7236..30c066fedee349ab8c344443b5de74d7108333a1 100644 (file)
@@ -811,7 +811,6 @@ unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current,
         Current.Previous->is(tok::at)) {
       IsNSStringLiteral = true;
       Prefix = "@\"";
-      --StartColumn;
     }
     if ((Text.endswith(Postfix = "\"") &&
          (IsNSStringLiteral || Text.startswith(Prefix = "\"") ||
index 08a77764ee87c51cea308f1479821a5229296e9a..33cc7eb7187fcce6406f2f3d2114628e70922bd7 100644 (file)
@@ -6266,7 +6266,7 @@ TEST_F(FormatTest, BreaksWideAndNSStringLiterals) {
             format("L\"wide string literal\";", getGoogleStyleWithColumns(16)));
   EXPECT_EQ("@\"NSString \"\n"
             "@\"literal\";",
-            format("@\"NSString literal\";", getGoogleStyleWithColumns(16)));
+            format("@\"NSString literal\";", getGoogleStyleWithColumns(19)));
 }
 
 TEST_F(FormatTest, BreaksRawStringLiterals) {