clang-format: Fix assertion on incomplete string literals.

Before, this could would lead to an assert:
  llvm::errs() << "
               << a;

llvm-svn: 191639
This commit is contained in:
Daniel Jasper 2013-09-29 12:02:57 +00:00
parent 0f01d4e309
commit 0b1f76b658
2 changed files with 10 additions and 1 deletions

View File

@ -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;

View File

@ -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) {