From 3dcd7eca7aa23beecfb59e0757e4c56ef8e6f149 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 2 Aug 2013 11:01:15 +0000 Subject: [PATCH] clang-format: Fix string breaking after "<<". Before, clang-format would not break overly long string literals following a "<<" with FormatStyle::AlwaysBreakBeforeMultilineStrings being set. llvm-svn: 187650 --- clang/lib/Format/Format.cpp | 2 +- clang/unittests/Format/FormatTest.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index b2bf3fe..02cbc31 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -936,7 +936,7 @@ private: State.NextToken = State.NextToken->Next; if (!Newline && Style.AlwaysBreakBeforeMultilineStrings && - Current.is(tok::string_literal)) + Current.is(tok::string_literal) && Current.CanBreakBefore) return 0; return breakProtrudingToken(Current, State, DryRun); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 3a3164c..ba78995 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -5167,6 +5167,11 @@ TEST_F(FormatTest, BreakStringLiterals) { "aaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa " "aaaaaaaaaaaaaaaaaaaaaa\");", getGoogleStyle())); + EXPECT_EQ("llvm::outs() << \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \"\n" + " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\";", + format("llvm::outs() << " + "\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaa\";")); FormatStyle AlignLeft = getLLVMStyleWithColumns(12); AlignLeft.AlignEscapedNewlinesLeft = true; -- 2.7.4