-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Template arguments can't be used in attributes #67154
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
Comments
@llvm/issue-subscribers-clang-frontend
```
constexpr int constexpr_var = 101;
[[gnu::constructor(constexpr_var)]] void a() {}
template <int TemplateArg> template void b<101>();
|
It looks like the diagnostic is from CC @erichkeane @AaronBallman who may know if this is a purposeful restriction or not. |
It's in |
Was just confirming that :) yeah, unfortunately the infrastructure to have attributes work with templates is pretty manual, so each individual attribute has to be programmed to work with template arguments individually. In this case, the There's quite a few examples on how to do it, but GuardedBy is pretty easy to copy, as this should be. Basically, the 'handle' function will be called 1x for uninstantiated, then 1x for each instantiation, and can be re-checked. This isn't a bad 'beginner' bug if this is important to you. |
@llvm/issue-subscribers-good-first-issue
```c++
constexpr int constexpr_var = 101;
[[gnu::constructor(constexpr_var)]] void a() {}
template <int TemplateArg> template void b<101>();
|
Can I have a go at this? :) |
@jmintb Of course! |
Ah yes I missed that, my bad |
@jmintb sorry for the late reply. Feel free to commandeer that patch. I likely won't have time to look at it for a little while |
Unassigning as @jmintb seems to have not made progress on this in more than a year. Feel free to ask for reassignment if you wish to pick this up/pick this up again! |
This code compiles fine with gcc, and clang can successfully compile
a
but errors onb
with "'constructor' attribute requires an integer constant".Note clang doesn't error on the instantiation of b but rather on the template definition. so even if the
template void b<101>();
line is removed clang still gives an error.The text was updated successfully, but these errors were encountered: