Home>

In visual_studio this code works fine

template<class T>class Interface{
  public:
    constexpr Interface() noexcept {
      static_cast<void>(&
T::foo); //Check if type 'T' has function 'foo'
    }
};

But in clang++ it throws an error

error : address of overloaded function 'foo' cannot be static_cast to type 'void'

Maybe clang doesn't support such a feature?

p.s. Instead ofvoidframedvoid*,void(*)(),long long,uintptr_t. I also tried replacingstatic_caston thereinterpret_castand to cast in C style. Nothing helped.

p.p.s.

clang version 13.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix

Replace void with the required type &T::foo.

user78606702022-01-14 09:42:02

&T::foo is an address, not a type

Anton Mitrochin2022-01-14 09:47:07

&T::foo is an expression, and like any expression, it has a type. And this type must be specified explicitly when the address of an overloaded function is taken to select a specific overload.

user78606702022-01-14 09:49:11