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();
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();
"}");
}
-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) {