diff --git a/src/wasm-type-printing.h b/src/wasm-type-printing.h index 483c48cf0a3..377cda2e6e6 100644 --- a/src/wasm-type-printing.h +++ b/src/wasm-type-printing.h @@ -17,6 +17,7 @@ #ifndef wasm_wasm_type_printing_h #define wasm_wasm_type_printing_h +#include #include #include #include @@ -34,9 +35,6 @@ namespace wasm { template struct TypeNameGeneratorBase { TypeNameGeneratorBase() { assertValidUsage(); } - TypeNames getNames(HeapType type) { - WASM_UNREACHABLE("Derived class must implement getNames"); - } HeapType::Printed operator()(HeapType type) { return type.print( [&](HeapType ht) { return static_cast(this)->getNames(ht); }); @@ -48,16 +46,9 @@ template struct TypeNameGeneratorBase { private: constexpr void assertValidUsage() { - // This check current causes a crash on MSVC - // TODO: Convert to C++20 requires check -#if !defined(_MSC_VER) && (!defined(__GNUC__) || __GNUC__ >= 14) - // Check that the subclass provides `getNames` with the correct type. - using Self = TypeNameGeneratorBase; - static_assert( - static_cast(&Self::getNames) != - static_cast(&Subclass::getNames), - "Derived class must implement getNames"); -#endif + static_assert(requires(Subclass& s, HeapType ht) { + { s.getNames(ht) } -> std::same_as; + }, "Derived class must implement getNames"); } }; @@ -123,11 +114,8 @@ struct ModuleTypeNameGenerator ModuleTypeNameGenerator(const Module& wasm, FallbackGenerator& fallback) : wasm(wasm), fallback(fallback) {} - // TODO: Use C++20 `requires` to clean this up. - template - ModuleTypeNameGenerator( - const Module& wasm, - std::enable_if_t>* = nullptr) + ModuleTypeNameGenerator(const Module& wasm) + requires std::is_same_v : ModuleTypeNameGenerator(wasm, defaultGenerator) {} TypeNames getNames(HeapType type) {