From: Daniel Jasper Date: Tue, 14 Jan 2014 09:53:07 +0000 (+0000) Subject: clang-format: Fix bug introduced in r198871. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cc6af3af2ff31b91f778bcd257bea3d4196c7b9e;p=clang clang-format: Fix bug introduced in r198871. 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 --- diff --git a/lib/Format/BreakableToken.cpp b/lib/Format/BreakableToken.cpp index 8ca97d37a2..03693c62bb 100644 --- a/lib/Format/BreakableToken.cpp +++ b/lib/Format/BreakableToken.cpp @@ -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) { diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index aaedceb31e..30c066fede 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -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 = "\"") || diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 08a77764ee..33cc7eb718 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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) {