On 7/1/21 5:28 AM, Matthias Kretz wrote:
On Tuesday, 22 June 2021 22:12:42 CEST Jason Merrill wrote:
On 6/22/21 4:01 PM, Matthias Kretz wrote:
On Tuesday, 22 June 2021 21:52:16 CEST Jason Merrill wrote:
For alias templates, you probably want the attribute only on the
templated class, not on the instantiations.
Oh good point. My current patch does not allow the attribute on alias
templates. Consider:
template <class T, class U>
struct X {};
template <class T>
using foo [[gnu::diagnose_as]] = X<T, int>;
I have no idea how this could work. I would have to set the attribute for
an implicit partial specialization (not that I know of the existence of
such a thing)? I.e. X<int, int> would have to be diagnosed as foo<int>,
but X<int, float> would have to be diagnosed as X<int, float>, not foo.
So if anything it should only support alias templates if they are strictly
"renaming" the type. I.e. their template parameters must match up exactly.
Can I constrain the attribute like this?
Yes. You can check that with get_underlying_template.
Or you could support the above by putting the attribute on the
instantiation with the TEMPLATE_INFO for foo<A> rather than a simple name.
Question, given:
template <class T> using foo = bar<T>;
The diagnose_as attribute handler isn't called until e.g. `foo<int>` is
instantiated.
You probably want to adjust is_late_template_attribute to change that.
Meaning that even after the declaration of the alias template
`bar<int>` will not be diagnosed as `foo<int>`, which happens only after the
first use of `foo<int>`. I find that more confusing than helpful, even if the
expectation would be that users only use the alias template.
So do you still expect alias templates to support diagnose_as? And if yes, how
could I handle the attribute so that the diagnose_as attribute is applied to
`bar` on declaration of `foo`?