Skip to content

Commit b877cfa

Browse files
authored
[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
1 parent b69dcb8 commit b877cfa

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

clang/include/clang/Basic/Diagnostic.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -1429,16 +1429,19 @@ operator<<(const StreamingDiagnostic &DB, T *DC) {
14291429
return DB;
14301430
}
14311431

1432-
// Convert scope enums to their underlying type, so that we don't have
1432+
// Convert scoped enums to their underlying type, so that we don't have
14331433
// clutter the emitting code with `llvm::to_underlying()`.
14341434
// We also need to disable implicit conversion for the first argument,
14351435
// because classes that derive from StreamingDiagnostic define their own
14361436
// templated operator<< that accept a wide variety of types, leading
14371437
// to ambiguity.
1438-
template <typename T, typename U>
1438+
template <typename T, typename U,
1439+
typename UnderlyingU = typename std::enable_if_t<
1440+
std::is_enum_v<std::remove_reference_t<U>>,
1441+
std::underlying_type<std::remove_reference_t<U>>>::type>
14391442
inline std::enable_if_t<
14401443
std::is_same_v<std::remove_const_t<T>, StreamingDiagnostic> &&
1441-
llvm::is_scoped_enum_v<std::remove_reference_t<U>>,
1444+
!std::is_convertible_v<U, UnderlyingU>,
14421445
const StreamingDiagnostic &>
14431446
operator<<(const T &DB, U &&SE) {
14441447
DB << llvm::to_underlying(SE);

llvm/include/llvm/ADT/STLForwardCompat.h

-5
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ struct from_range_t {
7272
explicit from_range_t() = default;
7373
};
7474
inline constexpr from_range_t from_range{};
75-
76-
template <typename T, typename UnderlyingT = std::underlying_type_t<T>>
77-
constexpr bool is_scoped_enum_v =
78-
std::is_enum_v<T> && !std::is_convertible_v<T, UnderlyingT>;
79-
8075
} // namespace llvm
8176

8277
#endif // LLVM_ADT_STLFORWARDCOMPAT_H

0 commit comments

Comments
 (0)