From: Jason Merrill <jason@redhat.com>
To: Matthias Kretz <m.kretz@gsi.de>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Add gnu::diagnose_as attribute
Date: Thu, 1 Jul 2021 11:18:26 -0400 [thread overview]
Message-ID: <16bf94b5-cda3-08df-144b-739fa1c0ce3f@redhat.com> (raw)
In-Reply-To: <2984128.Mn6ktlgx0N@excalibur>
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`?
>
next prev parent reply other threads:[~2021-07-01 15:18 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <14205410.xuKvIAzr1H@excalibur>
[not found] ` <20210427094648.GL3008@redhat.com>
2021-05-04 11:13 ` Matthias Kretz
2021-05-04 13:34 ` David Malcolm
2021-05-04 14:23 ` Matthias Kretz
2021-05-04 14:32 ` Matthias Kretz
2021-05-04 19:00 ` David Malcolm
2021-05-04 19:22 ` Matthias Kretz
2021-05-14 16:05 ` Martin Sebor
2021-05-26 21:33 ` Matthias Kretz
2021-05-27 17:39 ` Jason Merrill
2021-05-27 18:54 ` Matthias Kretz
2021-05-27 21:15 ` Jason Merrill
2021-05-27 22:07 ` Matthias Kretz
2021-05-28 3:05 ` Jason Merrill
2021-05-28 7:42 ` Matthias Kretz
2021-06-01 19:12 ` Jason Merrill
2021-06-01 21:01 ` Matthias Kretz
2021-06-11 10:01 ` Matthias Kretz
2021-06-15 15:51 ` Jason Merrill
2021-06-15 20:56 ` Matthias Kretz
2021-06-16 0:48 ` Jason Merrill
2021-06-22 7:30 ` Matthias Kretz
2021-06-22 19:52 ` Jason Merrill
2021-06-22 20:01 ` Matthias Kretz
2021-06-22 20:12 ` Jason Merrill
2021-07-01 9:28 ` Matthias Kretz
2021-07-01 15:18 ` Jason Merrill [this message]
2021-07-05 14:18 ` Matthias Kretz
2021-07-07 22:34 ` Jason Merrill
2021-07-07 8:23 ` Matthias Kretz
2021-07-08 1:19 ` Jason Merrill
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=16bf94b5-cda3-08df-144b-739fa1c0ce3f@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=m.kretz@gsi.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).