From: Daniel Jasper Date: Thu, 22 Mar 2018 14:43:54 +0000 (+0000) Subject: clang-format: Narrow down raw string literal line break exception. X-Git-Tag: llvmorg-7.0.0-rc1~9946 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fd327674dd52a5c77483bfe079237649476e6ea9;p=platform%2Fupstream%2Fllvm.git clang-format: Narrow down raw string literal line break exception. For multiline raw string literals, we generally want to respect the author's choice of linebreak before the 'R"(' as the rest of the raw string might be aligned to it and we cannot (commonly) modify the content. For single-line raw string literals, this doesn't make any sense and so we should just treat them as regular string literals in this regard. llvm-svn: 328201 --- diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 7fa2ff7..768c0a6 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2830,10 +2830,10 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, if (Style.BreakBeforeInheritanceComma && Right.is(TT_InheritanceComma)) return true; if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\"")) - // Raw string literals are special wrt. line breaks. The author has made a - // deliberate choice and might have aligned the contents of the string - // literal accordingly. Thus, we try keep existing line breaks. - return Right.NewlinesBefore > 0; + // Multiline raw string literals are special wrt. line breaks. The author + // has made a deliberate choice and might have aligned the contents of the + // string literal accordingly. Thus, we try keep existing line breaks. + return Right.IsMultiline && Right.NewlinesBefore > 0; if ((Right.Previous->is(tok::l_brace) || (Right.Previous->is(tok::less) && Right.Previous->Previous && Right.Previous->Previous->is(tok::equal))) && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index fa5506f..6fb2903 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -8106,6 +8106,9 @@ TEST_F(FormatTest, CountsCharactersInMultilineRawStringLiterals) { "multiline raw string literal xxxxxxxxxxxxxx\n" ")x\" + bbbbbb);", getGoogleStyleWithColumns(20))); + EXPECT_EQ("fffffffffff(R\"(single line raw string)\" + bbbbbb);", + format("fffffffffff(\n" + " R\"(single line raw string)\" + bbbbbb);")); } TEST_F(FormatTest, SkipsUnknownStringLiterals) {