https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71879
Bug ID: 71879 Summary: Error in unevaluated context breaks SFINAE Product: gcc Version: 6.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: manuel.schil...@bmw-carit.de Target Milestone: --- Having asked at Stackoverflow I was told the following might be a bug in GCC: -------- 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. /// #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, int) -> decltype( std::enable_if_t< std::is_same< decltype(&T::template foo<decltype(*this)>), void (T::*)(decltype(*this)) >::value >()) { //x.foo(*this); } template <typename T> void call(T&&, char){ std::cout << "hello" << std::endl;} }; int main() { Caller c; c.call(Foo(), 0); } /// Error message: main.cpp: In instantiation of 'void Foo::foo(T&&) [with T = Caller&]': main.cpp:14:14: required by substitution of 'template<class T> decltype (std::enable_if_t<std::is_same<decltype (& T:: foo<Caller&>), void (T::*)(Caller&)>::value>()) Caller::call(T&&, int) [with T = Foo]' main.cpp:31:18: required from here main.cpp:6:47: error: 'struct Caller' has no member named 'hello' template <typename T> void foo(T&& x) { x.hello(); } ~~^~~~~ ------ version: g++ 6.1.0 flags: g++ -std=c++14 -O2 -Wall -pedantic -pthread main.cpp ------ Link to code on coliru: http://coliru.stacked-crooked.com/a/a984ad1ca2edcb0c Link to stackoverflow: http://stackoverflow.com/q/38371924/678093