commit 654f0c3862f7bae5bad07b4b451e10c9e9affa35 Author: Fujii Hironori Date: 2025-03-18T12:35:31-07:00 EnumTraits.h: error: no matching function for call to 'enumName' with Clang 20 https://bugs.webkit.org/show_bug.cgi?id=289669 Reviewed by Keith Miller. Clang 20 couldn't compile EnumTraits.h. > wtf/EnumTraits.h:212:33: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'V' An invalid enum value can't be specifed to the template parameter `V`. > template constexpr std::span enumName() The upstream Magic Enum C++ has a template variable `is_enum_constexpr_static_cast_valid` to check a enum value is valid. Imported the template variable. * Source/WTF/wtf/EnumTraits.h: (WTF::enumName): (WTF::makeEnumNames): Canonical link: https://commits.webkit.org/292321@main diff --git Source/WTF/wtf/EnumTraits.h Source/WTF/wtf/EnumTraits.h index 0d33e39a93dd..95e6318b6f1b 100644 --- Source/WTF/wtf/EnumTraits.h +++ Source/WTF/wtf/EnumTraits.h @@ -152,6 +152,16 @@ constexpr bool isZeroBasedContiguousEnum() #pragma clang diagnostic ignored "-Wenum-constexpr-conversion" #endif +#if COMPILER(CLANG) && __clang_major__ >= 16 +template +inline constexpr bool isEnumConstexprStaticCastValid = false; +template +inline constexpr bool isEnumConstexprStaticCastValid(V)>>> = true; +#else +template +inline constexpr bool isEnumConstexprStaticCastValid = true; +#endif + template constexpr std::span enumTypeNameImpl() { @@ -215,6 +225,15 @@ constexpr std::span enumName() return result; } +template +constexpr std::span enumName() +{ + if constexpr (isEnumConstexprStaticCastValid) + return enumName(V)>(); + else + return { }; +} + template constexpr std::underlying_type_t enumNamesMin() { @@ -264,7 +283,7 @@ constexpr auto makeEnumNames(std::index_sequence) { constexpr auto min = enumNamesMin(); return std::array, sizeof...(Is)> { - enumName(static_cast>(Is) + min)>()... + enumName>(Is) + min>()... }; }