clang-format: Merge labels and subsequent semicolons.
E.g.: default:; This can be used to get around restrictions as to what can follow a label. It fixes llvm.org/PR19648. llvm-svn: 236604
This commit is contained in:
parent
112b50e6b6
commit
1fe0d5ca59
|
@ -1896,7 +1896,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
|
|||
return false;
|
||||
if (Right.is(tok::colon)) {
|
||||
if (Line.First->isOneOf(tok::kw_case, tok::kw_default) ||
|
||||
!Right.getNextNonComment())
|
||||
!Right.getNextNonComment() || Right.getNextNonComment()->is(tok::semi))
|
||||
return false;
|
||||
if (Right.is(TT_ObjCMethodExpr))
|
||||
return false;
|
||||
|
|
|
@ -1381,6 +1381,8 @@ void UnwrappedLineParser::parseLabel() {
|
|||
}
|
||||
addUnwrappedLine();
|
||||
} else {
|
||||
if (FormatTok->is(tok::semi))
|
||||
nextToken();
|
||||
addUnwrappedLine();
|
||||
}
|
||||
Line->Level = OldLineLevel;
|
||||
|
|
|
@ -692,6 +692,11 @@ TEST_F(FormatTest, FormatsSwitchStatement) {
|
|||
" case OP_name: \\\n"
|
||||
" return operations::Operation##name\n",
|
||||
getLLVMStyleWithColumns(40));
|
||||
verifyFormat("switch (x) {\n"
|
||||
"case 1:;\n"
|
||||
"default:;\n"
|
||||
" int i;\n"
|
||||
"}");
|
||||
|
||||
verifyGoogleFormat("switch (x) {\n"
|
||||
" case 1:\n"
|
||||
|
@ -827,6 +832,11 @@ TEST_F(FormatTest, FormatsLabels) {
|
|||
"test_label:\n"
|
||||
" some_other_code();\n"
|
||||
"}");
|
||||
verifyFormat("{\n"
|
||||
" some_code();\n"
|
||||
"test_label:;\n"
|
||||
" int i = 0;\n"
|
||||
"}");
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
Loading…
Reference in New Issue