Created on 2021-11-01.00:00:00 last changed 16 months ago
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.
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.
Notes from the December, 2021 teleconference:
The consensus of CWG was to reject both examples, i.e., the first option.
[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:43 | admin | set | status: open -> c++23 |
2023-07-16 13:00:43 | admin | set | status: drwp -> open |
2023-02-18 18:43:04 | admin | set | status: dr -> drwp |
2022-11-25 05:14:04 | admin | set | status: ready -> dr |
2022-11-10 15:04:39 | admin | set | status: review -> ready |
2022-01-06 00:00:00 | admin | set | messages: + msg6609 |
2022-01-06 00:00:00 | admin | set | messages: + msg6608 |
2022-01-06 00:00:00 | admin | set | messages: + msg6607 |
2021-11-01 00:00:00 | admin | create |