[clang] d005be3 - [clang-format] Handle C# `goto case` constructs (#113257)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 22 18:39:35 PDT 2024
Author: Owen Pan
Date: 2024-10-22T18:39:32-07:00
New Revision: d005be33ee776c5d788693f5c1cf4f6bc242e13c
URL: https://github.com/llvm/llvm-project/commit/d005be33ee776c5d788693f5c1cf4f6bc242e13c
DIFF: https://github.com/llvm/llvm-project/commit/d005be33ee776c5d788693f5c1cf4f6bc242e13c.diff
LOG: [clang-format] Handle C# `goto case` constructs (#113257)
Fixes #113256.
Added:
Modified:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTestCSharp.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 0b74889a6b20cd..1d425ad23f5967 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1568,6 +1568,11 @@ void UnwrappedLineParser::parseStructuralElement(
}
parseCaseLabel();
return;
+ case tok::kw_goto:
+ nextToken();
+ if (FormatTok->is(tok::kw_case))
+ nextToken();
+ break;
case tok::kw_try:
case tok::kw___try:
if (Style.isJavaScript() && Line->MustBeDeclaration) {
diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp
index 0c5afa1524374d..151f7072e0c657 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -1689,15 +1689,25 @@ TEST_F(FormatTestCSharp, BrokenBrackets) {
}
TEST_F(FormatTestCSharp, GotoCaseLabel) {
- verifyNoCrash("switch (i) {\n"
- "case 0:\n"
- " goto case 1;\n"
- "case 1:\n"
- " j = 0;\n"
- " {\n"
- " break;\n"
- " }\n"
- "}");
+ verifyFormat("switch (i)\n"
+ "{\n"
+ "case 0:\n"
+ " goto case 1;\n"
+ "case 1:\n"
+ " j = 0;\n"
+ " {\n"
+ " break;\n"
+ " }\n"
+ "}",
+ "switch (i) {\n"
+ "case 0:\n"
+ " goto case 1;\n"
+ "case 1:\n"
+ " j = 0;\n"
+ " {\n"
+ " break;\n"
+ " }\n"
+ "}");
}
} // namespace
More information about the cfe-commits
mailing list