Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a parameter of a template template parameter cause shadowing?

Is this legal C++?

template <typename T, template <typename T> class>
struct S { };

Clang (3.7.1) rejects it, complaining the second T shadows the first T. GCC seems not to care about it and I think that's reasonable. I think it is only the number of parameters that matters in a template template parameter.

  • http://goo.gl/51bHVG (gcc.godbolt.org)
like image 937
nodakai Avatar asked Mar 02 '16 10:03

nodakai


People also ask

What is the role of parameter in a template?

An identifier that names a non-type template parameter of class type T denotes a static storage duration object of type const T, called a template parameter object, whose value is that of the corresponding template argument after it has been converted to the type of the template parameter.

Can a template be a template parameter?

A template argument for a template template parameter is the name of a class template. When the compiler tries to find a template to match the template template argument, it only considers primary class templates. (A primary template is the template that is being specialized.)

What can the template parameter in C++ template definition be?

A template parameter is a special kind of parameter that can be used to pass a type as argument: just like regular function parameters can be used to pass values to a function, template parameters allow to pass also types to a function.

What are non-type parameters for templates?

A template non-type parameter is a template parameter where the type of the parameter is predefined and is substituted for a constexpr value passed in as an argument. A non-type parameter can be any of the following types: An integral type. An enumeration type.


1 Answers

No. [temp.local]/6:

A template-parameter shall not be redeclared within its scope (including nested scopes).

like image 86
T.C. Avatar answered Sep 22 '22 08:09

T.C.