diff options
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 6 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 9 |
2 files changed, 14 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 9a52f826571..359923f02f8 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -415,6 +415,10 @@ private: } } else { while (CurrentToken != NULL) { + if (CurrentToken->is(tok::string_literal)) + // Mark these string literals as "implicit" literals, too, so that + // they are not split or line-wrapped. + CurrentToken->Type = TT_ImplicitStringLiteral; next(); } } @@ -1098,6 +1102,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, if (Right.is(tok::r_paren) || Right.is(tok::greater)) return false; + if (Left.is(tok::identifier) && Right.is(tok::string_literal)) + return true; return (isBinaryOperator(Left) && Left.isNot(tok::lessless)) || Left.is(tok::comma) || Right.is(tok::lessless) || Right.is(tok::arrow) || Right.is(tok::period) || diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 00657e046b5..3cf151e43f8 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -1460,6 +1460,11 @@ TEST_F(FormatTest, AlignsStringLiterals) { verifyFormat("a = a + \"a\"\n" " \"a\"\n" " \"a\";"); + + verifyFormat( + "#define LL_FORMAT \"ll\"\n" + "printf(\"aaaaa: %d, bbbbbb: %\" LL_FORMAT \"d, cccccccc: %\" LL_FORMAT\n" + " \"d, ddddddddd: %\" LL_FORMAT \"d\");"); } TEST_F(FormatTest, AlignsPipes) { @@ -1933,7 +1938,9 @@ TEST_F(FormatTest, HandlesIncludeDirectives) { "#include \"string.h\"\n" "#include \"string.h\"\n" "#include <a-a>\n" - "#include < path with space >\n"); + "#include < path with space >\n" + "#include \"some very long include paaaaaaaaaaaaaaaaaaaaaaath\"", + getLLVMStyleWithColumns(35)); verifyFormat("#import <string>"); verifyFormat("#import <a/b/c.h>"); |