Disclaimer: Maybe what I'm trying to do is prohibited by the standard, if so please let me know.
I'm trying to take the type of a virtual method (pointer) with decltype
within the scope of the class defining the method. This works fine with GCC, but hard crashes Visual Studio 2013:
class foo
{
public:
virtual void bar() = 0;
// typedef decltype(&foo::bar) bar_pointer; // crashes VS2013 (error C1001: An internal error has occurred in the compiler)
};
typedef decltype(&foo::bar) bar_pointer; // works fine with VS2013
For various reasons I need the type within the class, so I'm trying to work around this crash. Interestingly enough, the following compiles with VS2013:
class foo
{
public:
virtual void bar() = 0;
typedef decltype(foo::bar) bar_pointer; // works in VS2013, GCC complains(invalid use of non-static member function)
};
Here, the type of bar_pointer
comes out as void __thiscall foo::(void)
. Doesn't make much sense to me, I guess this is some erroneous type. Yet I tried to transform this type to a valid method pointer type by passing it to a template specialization which extracts return type and parameter types. But it seem like this weird type doesn't match any specialization I could come up with.
Does anyone have an idea what's going on here or can think of a way to workaround this issue?
UPDATE:
Seem like this is not directly related to decltype
, but to unevaluated contexts in general. The following also crashes:
class foo
{
public:
virtual void bar() = 0;
static const size_t test = sizeof(&foo::bar);
};