MSVC 2008 error "Type" is not a struct (although it is)

The following MWE compiles on gcc 4.8.2, but not on MSVC 2008 (company policy)

struct B
{
};

struct A
{
    typedef B Handler;
};

template<typename T>
struct Foo
{
    typedef typename T::Handler  Type;
};

template<typename T>
struct Bar
{
    friend struct Foo<T>::Type;     // MSVC 2008 does not like this
    typedef typename Foo<T>::Type   Foo;
};

int main() 
{
}

      

MSVC error 2008

error C2649: 'Foo<T>::Type' : is not a 'struct'

      

Is this a compiler error or am I doing something illegal here? More importantly, is there a fix?

+3


source to share


2 answers


Remove the keyword struct

and replace it with typename

:



template<typename T>
struct Bar
{
    friend typename Foo<T>::Type;     
    typedef typename Foo<T>::Type   Foo;
};

      

+6


source


This seems to be wrong. [Class.friend] / 3:

Ad

A friend

, which does not declare the function must have one of the following forms:
friend

the specified type specifier ;


friend

simple, of the type-specifier ;


friend

typename-specifier;


However, there is an important limitation on specifiers of the specified types: [dcl.type.elab] / 2:



If the identifier resolves to a typedef name [...] Designed type specifier is ill-formed.

GCC and Clang are wrong in this regard, and surprisingly, VC ++ is right.
You can use the third marker of the first quote and use the typename specifier.

friend typename Foo<T>::Type;

      

+4


source







All Articles