Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ lib/Format/ContinuationIndenter.cpp @@ -745,7 +745,11 @@ !Current.isOneOf(tok::colon, tok::comment)) return ContinuationIndent; if (State.Stack.back().Indent == State.FirstIndent && PreviousNonComment && - PreviousNonComment->isNot(tok::r_brace)) + PreviousNonComment->isNot(tok::r_brace) && + // Don't indent the second and next in a sequence of string literals. + // Such sequence might have been introduced by string literal breaking, + // so this is important to preserve idempotency. + !(PreviousNonComment->isStringLiteral() && Current.isStringLiteral())) // Ensure that we fall back to the continuation indent width instead of // just flushing continuations left. return State.Stack.back().Indent + Style.ContinuationIndentWidth; Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -6748,6 +6748,22 @@ format("\"test\\000000000001\"", getLLVMStyleWithColumns(10))); } +TEST_F(FormatTest, KeepsIndentInASequenceOfStringLiteralsTheSame) { + verifyFormat("\"line 1\"\n" + "\"line 2\""); + verifyFormat("f(\"line 1\"\n" + " \"line 2\");"); + verifyFormat("{\n" + " std::string a = \"line 1\"\n" + " \"line 2\"\n" + " \"line 3\";\n" + "}"); + verifyFormat("auto a = \"line 1\"\n" + " u\"line 2\";"); + verifyFormat("@\"line 1\"\n" + "@\"line 2\";"); +} + TEST_F(FormatTest, DoNotCreateUnreasonableUnwrappedLines) { verifyFormat("void f() {\n" " return g() {}\n" @@ -10098,7 +10114,6 @@ EXPECT_TRUE(static_cast(Result)); EXPECT_EQ(Expected, *Result); } - } // end namespace } // end namespace format } // end namespace clang