Skip to content

Commit 13c1c63

Browse files
kuhargithub-actions[bot]
authored andcommitted
Automerge: [ADT] Mark StringSwitch Cases with 6+ arguments as deprecated. NFC. (#163405)
Switch to the `.Cases({S0, S1, ...}, Value)` overload instead. Update existing uses affected by the deprecation and the surrounding code (for consistency). This is a part of a larger cleanup of StringSwitch. The goal is to eventually deprecate all manually-enumerated overloads of Cases with a hardcoded number of case values (in favor of passing them via an initializer list). You can find the full explanation here: llvm/llvm-project#163117. Start small (6+ arguments) to keep the number of changes manageable.
2 parents fac3930 + c4eaf56 commit 13c1c63

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

llvm/include/llvm/ADT/StringSwitch.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LLVM_ADT_STRINGSWITCH_H
1515

1616
#include "llvm/ADT/StringRef.h"
17+
#include "llvm/Support/Compiler.h"
1718
#include "llvm/Support/ErrorHandling.h"
1819
#include <cassert>
1920
#include <cstring>
@@ -38,7 +39,7 @@ namespace llvm {
3839
/// .Case("green", Green)
3940
/// .Case("blue", Blue)
4041
/// .Case("indigo", Indigo)
41-
/// .Cases("violet", "purple", Violet)
42+
/// .Cases({"violet", "purple"}, Violet)
4243
/// .Default(UnknownColor);
4344
/// \endcode
4445
template<typename T, typename R = T>
@@ -107,31 +108,36 @@ class StringSwitch {
107108
return CasesImpl(Value, {S0, S1, S2, S3, S4});
108109
}
109110

111+
[[deprecated("Pass cases in std::initializer_list instead")]]
110112
StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
111113
StringLiteral S3, StringLiteral S4, StringLiteral S5,
112114
T Value) {
113115
return CasesImpl(Value, {S0, S1, S2, S3, S4, S5});
114116
}
115117

118+
[[deprecated("Pass cases in std::initializer_list instead")]]
116119
StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
117120
StringLiteral S3, StringLiteral S4, StringLiteral S5,
118121
StringLiteral S6, T Value) {
119122
return CasesImpl(Value, {S0, S1, S2, S3, S4, S5, S6});
120123
}
121124

125+
[[deprecated("Pass cases in std::initializer_list instead")]]
122126
StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
123127
StringLiteral S3, StringLiteral S4, StringLiteral S5,
124128
StringLiteral S6, StringLiteral S7, T Value) {
125129
return CasesImpl(Value, {S0, S1, S2, S3, S4, S5, S6, S7});
126130
}
127131

132+
[[deprecated("Pass cases in std::initializer_list instead")]]
128133
StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
129134
StringLiteral S3, StringLiteral S4, StringLiteral S5,
130135
StringLiteral S6, StringLiteral S7, StringLiteral S8,
131136
T Value) {
132137
return CasesImpl(Value, {S0, S1, S2, S3, S4, S5, S6, S7, S8});
133138
}
134139

140+
[[deprecated("Pass cases in std::initializer_list instead")]]
135141
StringSwitch &Cases(StringLiteral S0, StringLiteral S1, StringLiteral S2,
136142
StringLiteral S3, StringLiteral S4, StringLiteral S5,
137143
StringLiteral S6, StringLiteral S7, StringLiteral S8,

0 commit comments

Comments
 (0)