Fix crash on invalid.

if { foo; }
would previously crash clang-format.

llvm-svn: 172232
This commit is contained in:
Manuel Klimek 2013-01-11 18:28:36 +00:00
parent d5e5f8f2a4
commit adededff26
2 changed files with 6 additions and 1 deletions

View File

@ -404,7 +404,8 @@ void UnwrappedLineParser::parseParens() {
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();

View File

@ -1108,6 +1108,10 @@ TEST_F(FormatTest, IncorrectCodeDoNoWhile) {
"}");
}
TEST_F(FormatTest, IncorrectIf) {
verifyFormat("if {\n foo;\n foo();\n}");
}
TEST_F(FormatTest, DoesNotTouchUnwrappedLinesWithErrors) {
verifyFormat("namespace {\n"
"class Foo { Foo ( }; } // comment");