Author: Vlad Serebrennikov Date: 2025-05-01T18:37:23+04:00 New Revision: b877cfa8f25412a3946d1cde63a1dad95fd95c90
URL: https://github.com/llvm/llvm-project/commit/b877cfa8f25412a3946d1cde63a1dad95fd95c90 DIFF: https://github.com/llvm/llvm-project/commit/b877cfa8f25412a3946d1cde63a1dad95fd95c90.diff LOG: [ADT] Remove `is_scoped_enum_v` (#138134) `std::underlying_type` is not SFINAE-friendly in Clang and GCC before 9, and it's too much of a hassle to make it work. Instead, I'm inlining the implementation in the only place it's needed. Fixes buildbot failure https://lab.llvm.org/buildbot/#/builders/134/builds/17904 caused by #138089. Demo: https://godbolt.org/z/9qo3csP98 Added: Modified: clang/include/clang/Basic/Diagnostic.h llvm/include/llvm/ADT/STLForwardCompat.h Removed: ################################################################################ diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h index 92ab61b95a7c6..0ba4edcc5d54c 100644 --- a/clang/include/clang/Basic/Diagnostic.h +++ b/clang/include/clang/Basic/Diagnostic.h @@ -1429,16 +1429,19 @@ operator<<(const StreamingDiagnostic &DB, T *DC) { return DB; } -// Convert scope enums to their underlying type, so that we don't have +// Convert scoped 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> +template <typename T, typename U, + typename UnderlyingU = typename std::enable_if_t< + std::is_enum_v<std::remove_reference_t<U>>, + std::underlying_type<std::remove_reference_t<U>>>::type> 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>>, + !std::is_convertible_v<U, UnderlyingU>, const StreamingDiagnostic &> operator<<(const T &DB, U &&SE) { DB << llvm::to_underlying(SE); diff --git a/llvm/include/llvm/ADT/STLForwardCompat.h b/llvm/include/llvm/ADT/STLForwardCompat.h index b8d4babc95fea..75a0d4acf67f1 100644 --- a/llvm/include/llvm/ADT/STLForwardCompat.h +++ b/llvm/include/llvm/ADT/STLForwardCompat.h @@ -72,11 +72,6 @@ struct from_range_t { explicit from_range_t() = default; }; inline constexpr from_range_t from_range{}; - -template <typename T, typename UnderlyingT = std::underlying_type_t<T>> -constexpr bool is_scoped_enum_v = - std::is_enum_v<T> && !std::is_convertible_v<T, UnderlyingT>; - } // namespace llvm #endif // LLVM_ADT_STLFORWARDCOMPAT_H _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits