[llvm] [AsmParser][NFCI] Restructure DiagnosticPredicate (PR #126653)
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 13 01:40:11 PST 2025
================
@@ -198,21 +192,36 @@ enum class DiagnosticPredicateTy {
// This is a light-weight alternative to the 'NearMissInfo' approach
// below which collects *all* possible diagnostics. This alternative
// is optional and fully backward compatible with existing
-// PredicateMethods that return a 'bool' (match or no match).
-struct DiagnosticPredicate {
- DiagnosticPredicateTy Type;
-
- explicit DiagnosticPredicate(bool Match)
- : Type(Match ? DiagnosticPredicateTy::Match
- : DiagnosticPredicateTy::NearMatch) {}
- DiagnosticPredicate(DiagnosticPredicateTy T) : Type(T) {}
- DiagnosticPredicate(const DiagnosticPredicate &) = default;
+// PredicateMethods that return a 'bool' (match or near match).
+class DiagnosticPredicate {
+ enum class PredicateTy {
+ Match, // Matches
+ NearMatch, // Close Match: use Specific Diagnostic
+ NoMatch, // No Match: use `InvalidOperand`
+ } Predicate;
+
+public:
+#if __cplusplus >= 202002L
+ using enum PredicateTy;
+#else
+ static constexpr PredicateTy Match = PredicateTy::Match;
+ static constexpr PredicateTy NearMatch = PredicateTy::NearMatch;
+ static constexpr PredicateTy NoMatch = PredicateTy::NoMatch;
+#endif
----------------
sdesmalen-arm wrote:
My preferred way forward would be to remove the bool constructor from `DiagnosticPredicate`; it seems wrong to always assume `NearMatch` rather than `NoMatch` for the `bool = false` case, but that will be a bigger change.
https://github.com/llvm/llvm-project/pull/126653
More information about the llvm-commits
mailing list