Boost logo

Boost :

Subject: Re: [boost] [scope_exit] C++11 freely uses typename (on MSVC10?)
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2012-04-02 23:22:33


>>> For example, is the following supposed to compile on MSVC10?
>>> #include <boost/mpl/identity.hpp>
>>>
>>> int main() {
>>> typedef typename boost::mpl::identity<int>::type t;
>>> t i = 0;
>>> return i;
>>> }
>>
>> This code does not compile on my copy of MSVC10.
>>
>> -->error C2899: typename cannot be used outside a template declaration
>>
>
> Thanks. Is anyone positive about what the C++11 standard says in this case?
> This code compiles on my GCC 4.5.3 with -std=c++0x... who's right MSVC or
> GCC?

C++03 section 14.2 paragraph 5 says:

"[Note: just as is the case with the typename prefix, the template prefix is
allowed in cases where it is not strictly necessary; i.e., when the expression
on the left of the -> or ., or the nested-name-specifier is not dependent on a
template-parameter.]"

C++11 amends this to:

"[Note: As is the case with the typename prefix, the template prefix is allowed
in cases where it is not strictly necessary; i.e., when the nested-name-specifier
or the expression on the left of the -> or . is not dependent on a
template-parameter, or the use does not appear in the scope of a template.]"

The addition of "or the use does not appear in the scope of a template" makes
your example valid in C++11 (but it was invalid in C++03).

It seems recent versions of GCC have adopted the C++11 behaviour, but MSVC has
not (yet, as of version 10).

Regards,
Nate
                                               


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk