http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46162
Summary: Invalid SFINAE with static member function/variable Product: gcc Version: 4.5.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: greg.r.rog...@gmail.com gcc rejects the following valid code, which compiles under clang, Comeau, and MSVC++. Expected output is "0 0". I am using gcc 4.5.1, I have not tried it on older versions. grog...@gazelle ~/junk $ cat junk.cpp #include <iostream> struct small_type { char dummy; }; struct large_type { char dummy[2]; }; template<class T> struct has_foo_member_variable { template<int T::*> struct tester; template<class U> static small_type has_foo(tester<&U::foo> *); template<class U> static large_type has_foo(...); static const bool value = (sizeof(has_foo<T>(0)) == sizeof(small_type)); }; struct A { static int foo() { return 0; } }; struct B { static int foo; }; int main() { std::cout << has_foo_member_variable<A>::value << ' ' << has_foo_member_variable<B>::value << '\n'; } grog...@gazelle ~/junk $ g++ junk.cpp junk.cpp: In instantiation of ‘const bool has_foo_member_variable<A>::value’: junk.cpp:30:46: instantiated from here junk.cpp:12:75: error: ‘A::foo’ is not a valid template argument for type ‘int A::*’ junk.cpp:12:75: error: it must be a pointer-to-member of the form `&X::Y' junk.cpp: In instantiation of ‘const bool has_foo_member_variable<B>::value’: junk.cpp:31:40: instantiated from here junk.cpp:12:75: error: ‘& B::foo’ is not a valid template argument for type ‘int B::*’ junk.cpp:12:75: error: it must be a pointer-to-member of the form `&X::Y' grog...@gazelle ~/junk $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/lto-wrapper Target: i686-pc-linux-gnu Configured with: ../configure --prefix=/usr --enable-languages=c,c++,fortran,objc,obj-c++,ada --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-gnu-unique-object --enable-lto --enable-plugin --disable-multilib --disable-libstdcxx-pch --with-system-zlib --with-ppl --with-cloog --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info Thread model: posix gcc version 4.5.1 (GCC) grog...@gazelle ~/junk $ uname -a Linux gazelle 2.6.35-ARCH #1 SMP PREEMPT Fri Aug 27 16:22:18 UTC 2010 i686 AMD Phenom(tm) 9950 Quad-Core Processor AuthenticAMD GNU/Linux