Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use [[clang::no_specializations]] to indicate templates which users are forbidden to specialize #5179

Open
CaseyCarter opened this issue Dec 11, 2024 · 0 comments
Labels
enhancement Something can be improved

Comments

@CaseyCarter
Copy link
Member

CaseyCarter commented Dec 11, 2024

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:

  • MSVC's diagnostics are restricted to just the subset of type traits that the compiler implements directly, whereas we could apply an attribute to every pertinent template in the Standard Library.
  • MSVC's diagnostics are triggered by existing Standard Library code that doesn't have suppression. (This is perhaps surprisingly a real issue, since Windows carries several old STL implementations for reasons.)

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.

@CaseyCarter CaseyCarter added the enhancement Something can be improved label Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something can be improved
Projects
None yet
Development

No branches or pull requests

1 participant