Created on 2022-06-23.00:00:00 last changed 17 months ago
Proposed resolution (approved by CWG 2022-11-09):
Change 13.9.4 [temp.expl.spec] paragraph 13 as follows:
Whether an explicit specialization of a function or variable template is inline, constexpr, or an immediate function is determined by the explicit specialization and is independent of those properties of the template. Similarly, attributes appearing in the declaration of a template have no effect on an explicit specialization of that template. [Example 7:template<class T> void f(T) { /* ... */ } template<class T> inline T g(T) { /* ... */ } template<> inline void f<>(int) { /* ... */ } // OK, inline template<> int g<>(int) { /* ... */ } // OK, not inline template<typename> [[noreturn]] void h([[maybe_unused]] int i); template<> void h<int>(int i) { // Implementations are expected not to warn that the function returns but can // warn about the unused parameter. }—end example]
Suggested resolution [SUPERSEDED]:
Change in 13.9.4 [temp.expl.spec] paragraph 13 as follows:
Any attributes applying to any part of the declaration of an explicit specialization of a function or variable template, as well asWhetherwhether such an explicit specializationof a function or variable templateis inline, constexpr, or an immediate function, is determined by the explicit specialization and is independent of those properties of the template. [ Note: Attributes that would affect the association of the declaration of an explicit specialization with the declaration of the primary template need to match. -- end note ]
[Accepted as a DR at the November, 2022 meeting.]
It is unclear whether an explicit template specialization "inherits" the attributes written on the primary template, or whether the specialization has to repeat the attributes. For example:
template <typename Ty>
[[noreturn]] void func(Ty);
template <>
void func<int>(int) {
// Warning about returning from a noreturn function or not?
}
A similar question arises for attributes written on the parameters of the primary function template. For example:
template <typename Ty>
void func([[maybe_unused]] int i);
template <>
void func<int>(int i) {
// i is not used, should it be warned on or not?
}
There is implementation divergence for the example.
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 14:41:10 | admin | set | messages: + msg6993 |
2022-11-10 14:41:10 | admin | set | status: drafting -> ready |
2022-08-19 07:54:33 | admin | set | status: open -> drafting |
2022-06-24 08:14:12 | admin | set | messages: + msg6867 |
2022-06-23 00:00:00 | admin | create |