Title
Restrictions on uses of template parameter names
Status
c++23
Section
13.8.2 [temp.local]
Submitter
Daveed Vandevoorde

Created on 2021-11-01.00:00:00 last changed 16 months ago

Messages

Date: 2021-12-15.00:00:00

Proposed resolution (December, 2021):

Change 13.8.2 [temp.local] paragraph 6 as follows:

The name of a template-parameter shall not be bound to any following declaration whose locus is contained by the scope to which the template-parameter belongs.
Date: 2021-12-15.00:00:00

Additional note (December, 2021):

It was observed that this issue is, strictly speaking, not a defect: the word “contains” is used in 6.4.1 [basic.scope.scope] paragraph 1 in its usual English sense to refer to the lexical nesting of scopes, so the template parameter scope of T “contains” the declaration of the function T. However, the use of the term “locus” would make the intent clearer.

Date: 2021-12-15.00:00:00

Notes from the December, 2021 teleconference:

The consensus of CWG was to reject both examples, i.e., the first option.

Date: 2022-11-15.00:00:00

[Accepted as a DR at the November, 2022 meeting.]

The status of an example like the following is unclear:

  template<typename T> T T(T) {}

According to 13.8.2 [temp.local] paragraph 6,

The name of a template-parameter shall not be bound to any following declaration contained by the scope to which the template-parameter belongs. [Example 5:

  ...
  template<class X> class X; // error: hidden by template-parameter

end example]

The intent would appear to be that the function template could not have the same name as the template parameter. However, according to 6.4.9 [basic.scope.temp] paragraph 2,

Each template-declaration D introduces a template parameter scope that extends from the beginning of its template-parameter-list to the end of the template-declaration. Any declaration outside the template-parameter-list that would inhabit that scope instead inhabits the same scope as D.

This would indicate that the function template inhabits the namespace scope, not the template parameter scope, so the prohibition against use of the template parameter name would not apply.

To reject both the function and class template examples, 13.8.2 [temp.local] paragraph 6 could be changed to read:

The name of a template-parameter shall not be bound to any following declaration whose locus is contained by the scope to which the template-parameter belongs.

To accept both examples, the change could be:

The name of a template-parameter shall not be bound to any following declaration that inhabits a scope contained by the scope to which the template-parameter belongs.
History
Date User Action Args
2023-07-16 13:00:43adminsetstatus: open -> c++23
2023-07-16 13:00:43adminsetstatus: drwp -> open
2023-02-18 18:43:04adminsetstatus: dr -> drwp
2022-11-25 05:14:04adminsetstatus: ready -> dr
2022-11-10 15:04:39adminsetstatus: review -> ready
2022-01-06 00:00:00adminsetmessages: + msg6609
2022-01-06 00:00:00adminsetmessages: + msg6608
2022-01-06 00:00:00adminsetmessages: + msg6607
2021-11-01 00:00:00admincreate