r191639 - clang-format: Fix assertion on incomplete string literals.
Daniel Jasper
djasper at google.com
Sun Sep 29 05:02:57 PDT 2013
Author: djasper
Date: Sun Sep 29 07:02:57 2013
New Revision: 191639
URL: http://llvm.org/viewvc/llvm-project?rev=191639&view=rev
Log:
clang-format: Fix assertion on incomplete string literals.
Before, this could would lead to an assert:
llvm::errs() << "
<< a;
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=191639&r1=191638&r2=191639&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sun Sep 29 07:02:57 2013
@@ -1161,7 +1161,11 @@ unsigned TokenAnnotator::splitPenalty(co
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;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=191639&r1=191638&r2=191639&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Sep 29 07:02:57 2013
@@ -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) {
More information about the cfe-commits
mailing list