Created on 2025-08-12.00:00:00 last changed 4 months ago
Consider:
template<typename T>
struct S {
static constexpr bool value = false;
};
template<typename T>
struct [[deprecated]] S<const T> {
static constexpr bool value = true;
};
static_assert(S<const int>::value, "BOOM!");
Should this trigger the deprecation warning for using the partial specialization? There is implementation divergence.
One consistent approach (used by clang) is to instantiate a declaration of the specialization from the primary template, but to instantiate the definition from the applicable partial specialization. Thus, [[deprecate]] on a partial specialization comes into effect when its definition is instantiated. However, C++ has some situations where a definition is surprisingly required, e.g.:
void f(...);
template<typename T>
struct S {
static constexpr bool value = false;
};
template<typename T>
struct [[deprecated]] S<const T> {
static constexpr bool value = true;
};
S<const int> *p;
void g() { f(p); }
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2025-08-12 00:00:00 | admin | create | |