summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-09-29 12:02:57 +0000
committerDaniel Jasper <djasper@google.com>2013-09-29 12:02:57 +0000
commit0b1f76b658ec6966a67164dc8c7c55a8960b1917 (patch)
tree7cd468bc552b30e3c16913e29bf813739e75befc
parent0f01d4e3090cc8ddeee1083c227c460e591af1f2 (diff)
downloadbcm5719-llvm-0b1f76b658ec6966a67164dc8c7c55a8960b1917.tar.gz
bcm5719-llvm-0b1f76b658ec6966a67164dc8c7c55a8960b1917.zip
clang-format: Fix assertion on incomplete string literals.
Before, this could would lead to an assert: llvm::errs() << " << a; llvm-svn: 191639
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp6
-rw-r--r--clang/unittests/Format/FormatTest.cpp5
2 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 992104fe4c2..6772c894dc0 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1161,7 +1161,11 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
if (Right.is(tok::lessless)) {
if (Left.is(tok::string_literal)) {
StringRef Content = Left.TokenText;
- Content = Content.drop_back(1).drop_front(1).trim();
+ if (Content.startswith("\""))
+ Content = Content.drop_front(1);
+ if (Content.endswith("\""))
+ Content = Content.drop_back(1);
+ Content = Content.trim();
if (Content.size() > 1 &&
(Content.back() == ':' || Content.back() == '='))
return 25;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 08b5643ac08..833a87c4fd0 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -3398,6 +3398,11 @@ TEST_F(FormatTest, AlignsPipes) {
verifyFormat(
"llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
" .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();");
+
+ // Incomplete string literal.
+ EXPECT_EQ("llvm::errs() << \"\n"
+ " << a;",
+ format("llvm::errs() << \"\n<<a;"));
}
TEST_F(FormatTest, UnderstandsEquals) {
OpenPOWER on IntegriCloud