Question Details

No question body available.

Tags

c++ templates

Answers (1)

February 5, 2026 Score: 6 Rep: 48,914 Quality: Medium Completeness: 70%

You can use the [[deprecated]] in the said explicit specialization(s) as shown below:

template struct C
{

}; template struct [[deprecated]] C{}; C< bool, 5> obj1; //gives warning

template struct C{};

C obj2; //no warning

Working demo. This works with all three compilers(gcc, clang and msvc). With this gcc will generate the following warning:

warning: 'C' is deprecated [-Wdeprecated-declarations]
    6 | C< bool, 5> obj_1; //gives warning
      |             ^~~~

Note that with msvc you'll need to use /W3.