Use [[clang::no_specializations]]
to indicate templates which users are forbidden to specialize
#5179
Labels
enhancement
Something can be improved
Clang has recently added support for a new attribute
[[clang::no_specializations]]
. (With an ugly equivalent[[_Clang::__no_specializations__]]
.) This is very similar in effect to the warning C5278 "adding a specialization for 'type trait' has undefined behavior" that MSVC added even more recently. MSVC's approach has some shortcomings:We should add attribute annotations to our headers to use the Clang attribute. I assume we can detect support with
__has_attribute(_Clang::__no_specializations__)
. This work will need to be verified with Clang 20. MSVC will likely implement a similar attribute in the near future, so these header annotations will do double duty.The attribute takes an optional string literal argument (a la
[[nodiscard("Who would discard a kitten, you monster!")]]
) that is included in the error message, which we should bear in mind while doing this work.The text was updated successfully, but these errors were encountered: