Skip to content

Commit d005be3

Browse files
authored
[clang-format] Handle C# goto case constructs (#113257)
Fixes #113256.
1 parent b69ac31 commit d005be3

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,11 @@ void UnwrappedLineParser::parseStructuralElement(
15681568
}
15691569
parseCaseLabel();
15701570
return;
1571+
case tok::kw_goto:
1572+
nextToken();
1573+
if (FormatTok->is(tok::kw_case))
1574+
nextToken();
1575+
break;
15711576
case tok::kw_try:
15721577
case tok::kw___try:
15731578
if (Style.isJavaScript() && Line->MustBeDeclaration) {

clang/unittests/Format/FormatTestCSharp.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,15 +1689,25 @@ TEST_F(FormatTestCSharp, BrokenBrackets) {
16891689
}
16901690

16911691
TEST_F(FormatTestCSharp, GotoCaseLabel) {
1692-
verifyNoCrash("switch (i) {\n"
1693-
"case 0:\n"
1694-
" goto case 1;\n"
1695-
"case 1:\n"
1696-
" j = 0;\n"
1697-
" {\n"
1698-
" break;\n"
1699-
" }\n"
1700-
"}");
1692+
verifyFormat("switch (i)\n"
1693+
"{\n"
1694+
"case 0:\n"
1695+
" goto case 1;\n"
1696+
"case 1:\n"
1697+
" j = 0;\n"
1698+
" {\n"
1699+
" break;\n"
1700+
" }\n"
1701+
"}",
1702+
"switch (i) {\n"
1703+
"case 0:\n"
1704+
" goto case 1;\n"
1705+
"case 1:\n"
1706+
" j = 0;\n"
1707+
" {\n"
1708+
" break;\n"
1709+
" }\n"
1710+
"}");
17011711
}
17021712

17031713
} // namespace

0 commit comments

Comments
 (0)