diff options
author | Manuel Klimek <klimek@google.com> | 2013-01-11 18:28:36 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2013-01-11 18:28:36 +0000 |
commit | adededff2657833d4ee7cdaeeb5afe6707adbdb1 (patch) | |
tree | 6e19fdfa51b3cd111dfbadb3eebb87fadb3e0bb4 | |
parent | d5e5f8f2a47246275a34c01c3eb472267eb40f92 (diff) | |
download | bcm5719-llvm-adededff2657833d4ee7cdaeeb5afe6707adbdb1.tar.gz bcm5719-llvm-adededff2657833d4ee7cdaeeb5afe6707adbdb1.zip |
Fix crash on invalid.
if { foo; }
would previously crash clang-format.
llvm-svn: 172232
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 3 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 4 |
2 files changed, 6 insertions, 1 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 758f8193ca4..07ad7a7489e 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -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(); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 71fa83ccb14..6beee3186b7 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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"); |