Fix crashes in UnwrappedLineParser on missing parens.

llvm-svn: 172239
This commit is contained in:
Manuel Klimek 2013-01-11 19:23:05 +00:00
parent 2acb7b7bb1
commit 9fa8d5578d
2 changed files with 9 additions and 3 deletions

View File

@ -450,7 +450,8 @@ void UnwrappedLineParser::parseForOrWhileLoop() {
assert((FormatTok.Tok.is(tok::kw_for) || FormatTok.Tok.is(tok::kw_while)) &&
"'for' or 'while' expected");
nextToken();
parseParens();
if (FormatTok.Tok.is(tok::l_paren))
parseParens();
if (FormatTok.Tok.is(tok::l_brace)) {
parseBlock();
addUnwrappedLine();
@ -510,7 +511,8 @@ void UnwrappedLineParser::parseCaseLabel() {
void UnwrappedLineParser::parseSwitch() {
assert(FormatTok.Tok.is(tok::kw_switch) && "'switch' expected");
nextToken();
parseParens();
if (FormatTok.Tok.is(tok::l_paren))
parseParens();
if (FormatTok.Tok.is(tok::l_brace)) {
parseBlock(Style.IndentCaseLabels ? 2 : 1);
addUnwrappedLine();

View File

@ -1114,8 +1114,12 @@ TEST_F(FormatTest, IncorrectCodeDoNoWhile) {
"}");
}
TEST_F(FormatTest, IncorrectIf) {
TEST_F(FormatTest, IncorrectCodeMissingParens) {
verifyFormat("if {\n foo;\n foo();\n}");
verifyFormat("switch {\n foo;\n foo();\n}");
verifyFormat("for {\n foo;\n foo();\n}");
verifyFormat("while {\n foo;\n foo();\n}");
verifyFormat("do {\n foo;\n foo();\n} while;");
}
TEST_F(FormatTest, DoesNotTouchUnwrappedLinesWithErrors) {