[clang] [llvm] [clang] Add scoped enum support to `StreamingDiagnostic` (PR #138089)
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Thu May 1 03:09:44 PDT 2025
================
@@ -1429,6 +1429,22 @@ operator<<(const StreamingDiagnostic &DB, T *DC) {
return DB;
}
+// Convert scope enums to their underlying type, so that we don't have
+// clutter the emitting code with `llvm::to_underlying()`.
+// We also need to disable implicit conversion for the first argument,
+// because classes that derive from StreamingDiagnostic define their own
+// templated operator<< that accept a wide variety of types, leading
+// to ambiguity.
+template <typename T, typename U>
+inline std::enable_if_t<
+ std::is_same_v<std::remove_const_t<T>, StreamingDiagnostic> &&
+ llvm::is_scoped_enum_v<std::remove_reference_t<U>>,
+ const StreamingDiagnostic &>
+operator<<(const T &DB, U &&SE) {
----------------
Endilll wrote:
I tried that. First you add an overload, then you need to modify the existing overload to not be a viable candidate when a scoped enum is passed. The new overload also have to copy any checks or asserts that the old one does, otherwise they will be skipped. I wasn't able to make it work, and it would be more complicated than the approach here anyway.
https://github.com/llvm/llvm-project/pull/138089
More information about the cfe-commits
mailing list