https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/113257

Fixes #113256.

>From ae702403b55b23074dd881ef7735bfbe0a3c8eab Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpi...@gmail.com>
Date: Mon, 21 Oct 2024 20:18:43 -0700
Subject: [PATCH] [clang-format] Handle C# `goto case` constructs

Fixes #113256.
---
 clang/lib/Format/UnwrappedLineParser.cpp    |  5 ++++
 clang/unittests/Format/FormatTestCSharp.cpp | 28 ++++++++++++++-------
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 4a5109983dfcc5..ebb9f4c7da8313 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

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to