From 20376989402fb187c0bc48209f46560b9e402ea2 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Sun, 29 Sep 2013 12:02:57 +0000 Subject: [PATCH] clang-format: Fix assertion on incomplete string literals. Before, this could would lead to an assert: llvm::errs() << " << a; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191639 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 6 +++++- unittests/Format/FormatTest.cpp | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 992104fe4c..6772c894dc 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 08b5643ac0..833a87c4fd 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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<