[llvm] [ADT] Deprecate StringSwitch Cases with 4+ args. NFC. (PR #164276)

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 20 09:08:57 PDT 2025


https://github.com/kuhar created https://github.com/llvm/llvm-project/pull/164276

Suggest the `initializer_list` overload instead.

4+ args is an arbitrary number that allows for incremental deprecation without having too update too many call sites.

For more context, see https://github.com/llvm/llvm-project/pull/163117.

>From 9777ace3aedfe438252306b992e8c30875cf5fff Mon Sep 17 00:00:00 2001
From: Jakub Kuderski <jakub at nod-labs.com>
Date: Mon, 20 Oct 2025 12:06:07 -0400
Subject: [PATCH] [ADT] Deprecate StringSwitch Cases with 4+ args. NFC.

Suggest the `initializer_list` overload instead.

4+ args is an arbitrary number that allows for incremental deprecation
without having too update too many call sites.

For more context, see https://github.com/llvm/llvm-project/pull/163117.
---
 llvm/include/llvm/ADT/StringSwitch.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/llvm/include/llvm/ADT/StringSwitch.h b/llvm/include/llvm/ADT/StringSwitch.h
index 26d568298207e..2262b1162e330 100644
--- a/llvm/include/llvm/ADT/StringSwitch.h
+++ b/llvm/include/llvm/ADT/StringSwitch.h
@@ -98,11 +98,13 @@ class StringSwitch {
     return CasesImpl({S0, S1, S2}, Value);
   }
 
+  [[deprecated("Pass cases in std::initializer_list instead")]]
   StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
                       StringLiteral S3, T Value) {
     return CasesImpl({S0, S1, S2, S3}, Value);
   }
 
+  [[deprecated("Pass cases in std::initializer_list instead")]]
   StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
                       StringLiteral S3, StringLiteral S4, T Value) {
     return CasesImpl({S0, S1, S2, S3, S4}, Value);
@@ -179,11 +181,13 @@ class StringSwitch {
     return CasesLowerImpl({S0, S1, S2}, Value);
   }
 
+  [[deprecated("Pass cases in std::initializer_list instead")]]
   StringSwitch &CasesLower(StringLiteral S0, StringLiteral S1, StringLiteral S2,
                            StringLiteral S3, T Value) {
     return CasesLowerImpl({S0, S1, S2, S3}, Value);
   }
 
+  [[deprecated("Pass cases in std::initializer_list instead")]]
   StringSwitch &CasesLower(StringLiteral S0, StringLiteral S1, StringLiteral S2,
                            StringLiteral S3, StringLiteral S4, T Value) {
     return CasesLowerImpl({S0, S1, S2, S3, S4}, Value);



More information about the llvm-commits mailing list