http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46764

           Summary: std=c++0x causes compilation failure on SFINAE test
                    for methods
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: bisq...@iki.fi


This code tests whether a class defines a method of a certain name or not.
It fails to compile on GCC when -std=c++0x is used. Without -std=c++0x, it
compiles and works fine.

#include <iostream>

struct Hello { int helloworld() { return 0; } };
struct Generic {};

// SFINAE test
template <typename T>
class has_helloworld
{
    typedef char yes;
    typedef struct { char dummy[2]; } no;

    template <typename C> static  yes test( typeof(&C::helloworld) ) ;
    template <typename C> static   no test(...);

public:
    enum { value = sizeof(test<T>(0)) == sizeof(yes) };
};

int main()
{
    std::cout << has_helloworld<Hello>::value << std::endl;
    std::cout << has_helloworld<Generic>::value << std::endl;
    return 0;
}

With -std=c++0x, we get the following error message:

tmp5.cc:13:68: error: ISO C++ forbids in-class initialization of non-const
static member 'test'
tmp5.cc:13:68: error: template declaration of 'has_helloworld::yes test'

Without -std=c++0x, the code compiles without warnings.

Indicating that GCC misinterprets test() to be a member/variable initialization
rather than a method/function declaration, despite the parameter expression
yielding a type rather than a value.

Reply via email to