While continuing work from my previous question, I came across different behavior of clang and GCC.
I need to check the member function pointer because I need to know if the function is inherited or not.
When comparing member function pointers in an SFINAE context, member function Foo::foo()
exists, but its body contains code (x.hello()
) which eventually does not compile.
The following code compiles with clang.
GCC however seems to evaluate the function body of Foo::foo()
and exits with an error ('struct Caller' has no member named 'hello'
), despite being in an unevaluated SFINAE context (or so I hope).
#include <iostream>
#include <type_traits>
struct Foo
{
template <typename T> void foo(T&& x) { x.hello(); }
};
struct Caller
{
template <typename T>
auto call(T&& x) -> decltype(
std::enable_if_t<
std::is_same<
decltype(&T::template foo<decltype(*this)>),
void (T::*)(decltype(*this))
>::value
>())
{
//x.foo(*this);
}
};
int main()
{
Caller c;
c.call(Foo());
}
I tested with:
- clang 3.8.0
- g++ 6.1.0
Compiler options for both: -std=c++14 -O2 -Wall -pedantic -pthread
My questions:
- who is right? Clang or GCC?
- How can I get the code to compile with GCC?