forked from OSchip/llvm-project
clang-format: Support labels in brace-less ifs.
While I am not personally convinced about the usefulness of this construct, we should break it. Before: if (a) label: f(); After: if (a) label: f(); llvm-svn: 265545
This commit is contained in:
parent
0dbd37543c
commit
4060947289
|
@ -1010,6 +1010,7 @@ void UnwrappedLineParser::parseStructuralElement() {
|
|||
// not labels.
|
||||
Style.Language != FormatStyle::LK_JavaScript) {
|
||||
if (FormatTok->Tok.is(tok::colon) && !Line->MustBeDeclaration) {
|
||||
Line->Tokens.begin()->Tok->MustBreakBefore = true;
|
||||
parseLabel();
|
||||
return;
|
||||
}
|
||||
|
@ -1572,6 +1573,8 @@ void UnwrappedLineParser::parseLabel() {
|
|||
addUnwrappedLine();
|
||||
}
|
||||
Line->Level = OldLineLevel;
|
||||
if (FormatTok->isNot(tok::l_brace))
|
||||
parseStructuralElement();
|
||||
}
|
||||
|
||||
void UnwrappedLineParser::parseCaseLabel() {
|
||||
|
|
|
@ -301,6 +301,12 @@ TEST_F(FormatTest, FormatIfWithoutCompoundStatement) {
|
|||
" // comment\n"
|
||||
" f();",
|
||||
AllowsMergedIf);
|
||||
verifyFormat("{\n"
|
||||
" if (a)\n"
|
||||
" label:\n"
|
||||
" f();\n"
|
||||
"}",
|
||||
AllowsMergedIf);
|
||||
verifyFormat("if (a)\n"
|
||||
" ;",
|
||||
AllowsMergedIf);
|
||||
|
|
Loading…
Reference in New Issue