forked from OSchip/llvm-project
Fix crashes in UnwrappedLineParser on missing parens.
llvm-svn: 172239
This commit is contained in:
parent
2acb7b7bb1
commit
9fa8d5578d
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue