Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using decltype with member function pointers

I have some trouble using decltype for member function pointers:

#include <iostream>
#include <type_traits>

struct A
{
    void func1() {}
    typedef decltype(&A::func1) type;
};

int wmain(int argc, wchar_t* argv[])
{
    typedef decltype(&A::func1) type;

    //Case 1
    std::wcout
        << std::boolalpha
        << std::is_member_function_pointer<type>::value
        << std::endl;

    //Case 2
    std::wcout
        << std::boolalpha
        << std::is_member_function_pointer<A::type>::value
        << std::endl;

    system("pause");
    return 0;
}

Case 1 prints true as expected, but Case 2 prints false.

Is decltype stripping away the "member" property of a type? If so, why?

Also, is there a way to prevent this behavior? I need to get the type of a member function regardless of where I use decltype.

Please help.

EDIT:

Reported to Microsoft

like image 334
Nubcase Avatar asked Jul 02 '11 14:07

Nubcase


1 Answers

For the sake of formality (having an answer to the question), this appears to be a bug in VC2010's compiler. File a bug report so that Microsoft can fix it in the next version.

like image 141
Nicol Bolas Avatar answered Oct 05 '22 23:10

Nicol Bolas