Title
[[deprecated]] for class template partial specializations
Status
open
Section
9.13.4 [dcl.attr.deprecated]
Submitter
Jonathan Caves

Created on 2025-08-12.00:00:00 last changed 2 weeks ago

Messages

Date: 2025-08-12.00:00:00

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:00admincreate