sfinae with decltype: bug in clang or gcc?
问题 Clang-3.2 can compile and code behave as expected: struct have_f { int f(int i) {return 10;} }; struct empty {}; template <class T> struct outer { T t; // if T have f(), define outer_f() template<class U=decltype(t.f(1))> int outer_f(int i) { return t.f(i); } }; int main() { outer<have_f> o1; outer<empty> o2; // to silence unused var warning return o1.outer_f(10) + sizeof(o2); } GCC of any version rejects with: t.cc:13:6: error: ‘struct empty’ has no member named ‘f’ int outer_f(int i) {