[PATCH] Add gnu::diagnose_as attribute
Jason Merrill
jason@redhat.com
Tue Jun 22 20:12:42 GMT 2021
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.
Jason
More information about the Libstdc++
mailing list