Is typedef a class template argument of the same name allowed?

This is similar to compiling and even working as expected in MSVC. But is it legal C ++ code and is it guaranteed to do what is expected here (i.e., Export the template type for users of the structure under the same name)?

template <typename EnumType>
struct Enum
{
   // There are two hard problems in CS: cache invalidation and naming things.
   typedef EnumType EnumType;
};
+4
source share
1 answer

I think type definition is not allowed.

14.6.1 Locally Declared Names (N4296)

6 The template parameter should not be redesigned within its scope (including nested areas). The template parameter must not have the same name as the template name. [Example:

 
template <class T, int i> class Y { 
   int T;  // error: template-parameter redeclared 
   void f() { 
       char T; // error: template-parameter redeclared 
   }
}; 

template<class X> class X;  // error: template-parameter redeclared

- ]

typedef EnumType EnumType - typedef-name.

+2

All Articles