[cfe-commits] r172232 - in /cfe/trunk: lib/Format/UnwrappedLineParser.cpp unittests/Format/FormatTest.cpp
Manuel Klimek
klimek at google.com
Fri Jan 11 10:28:37 PST 2013
Author: klimek
Date: Fri Jan 11 12:28:36 2013
New Revision: 172232
URL: http://llvm.org/viewvc/llvm-project?rev=172232&view=rev
Log:
Fix crash on invalid.
if { foo; }
would previously crash clang-format.
Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=172232&r1=172231&r2=172232&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Fri Jan 11 12:28:36 2013
@@ -404,7 +404,8 @@
void UnwrappedLineParser::parseIfThenElse() {
assert(FormatTok.Tok.is(tok::kw_if) && "'if' expected");
nextToken();
- parseParens();
+ if (FormatTok.Tok.is(tok::l_paren))
+ parseParens();
bool NeedsUnwrappedLine = false;
if (FormatTok.Tok.is(tok::l_brace)) {
parseBlock();
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172232&r1=172231&r2=172232&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Jan 11 12:28:36 2013
@@ -1108,6 +1108,10 @@
"}");
}
+TEST_F(FormatTest, IncorrectIf) {
+ verifyFormat("if {\n foo;\n foo();\n}");
+}
+
TEST_F(FormatTest, DoesNotTouchUnwrappedLinesWithErrors) {
verifyFormat("namespace {\n"
"class Foo { Foo ( }; } // comment");
More information about the cfe-commits
mailing list