diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 758f8193ca4f..07ad7a7489e0 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 71fa83ccb140..6beee3186b72 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");