From: Martin Sebor <msebor@gmail.com>
To: Jason Merrill <jason@redhat.com>, Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: Re: [C++ RFC] Fix up attribute handling in templates (PR c++/79502)
Date: Thu, 16 Feb 2017 23:17:00 -0000 [thread overview]
Message-ID: <904cf80e-7cd1-3451-f703-e4ea4916ef31@gmail.com> (raw)
In-Reply-To: <CADzB+2=6yb+1Jf2xA6to+UDHBh6sqVk1M4A0o8Q3nqdDa0Kvxw@mail.gmail.com>
On 02/16/2017 12:49 PM, Jason Merrill wrote:
> On Thu, Feb 16, 2017 at 11:33 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>> PR c++/79502
>> * pt.c (apply_late_template_attributes): If there are
>> no dependent attributes, set *p to attributes. If there were
>> some attributes in *p previously with or without dependent
>> attributes, chain them after the new attributes.
>
> Here's the variant of your patch that I'm applying.
Sorry to butt in but I feel like I'm missing something basic. Are
these attributes (nodiscard, noreturn, maybe_unused, and deprecated)
meant to apply to templates? The text in for nodiscard suggests
they're not:
The attribute-token nodiscard may be applied to the declarator-id
in a function declaration or to the declaration of a class or
enumeration.
Noreturn also doesn't mention templates:
The attribute may be applied to the declarator-id in a function
declaration.
Deprecated explicitly mentions template specializations but not
primary templates:
The attribute may be applied to the declaration of a class,
a typedef-name, a variable, a non-static data member, a function,
a namespace, an enumeration, an enumerator, or a template
specialization.
I can certainly see how applying attributes to the primary template
would be useful so it's puzzling to me that the standard seems to
preclude it.
I ask also because I was just looking at bug 79021 and scratching
my head about what to thing about it. While trying to understand
how GCC handles attributes for the primary template I came across
what doesn't make sense to me. Why would it apply the attribute
from the primary to the explicit specialization when the two are
distinct entities? Is that a bug?
template <class T>
[[noreturn]] int f () { throw ""; }
template <> int f<void> () { return 0; }
t.C: In function ‘int f() [with T = void]’:
t.C:4:37: warning: function declared ‘noreturn’ has a ‘return’ statement
template <> int f<void> () { return 0; }
^
t.C:4:37: warning: ‘noreturn’ function does return
template <> int f<void> () { return 0; }
^
Clang complains on this too with similar errors, but then GCC
silently accepts this code (which makes sense to me) which Clang
5 rejects with what looks like a bug:
template <class T>
int g () { return 0; }
template <> [[noreturn]] int g<void> () { throw ""; }
template <> [[noreturn]] int g<int> () { throw ""; }
Thanks
Martin
next prev parent reply other threads:[~2017-02-16 23:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-14 20:23 Jakub Jelinek
2017-02-15 17:02 ` Jason Merrill
2017-02-15 18:01 ` Jakub Jelinek
2017-02-15 20:23 ` Jason Merrill
2017-02-16 16:08 ` Jakub Jelinek
2017-02-16 16:38 ` Jakub Jelinek
2017-02-16 20:16 ` Jason Merrill
2017-02-16 23:17 ` Martin Sebor [this message]
2017-02-18 5:39 ` Jason Merrill
2017-02-19 21:56 ` Martin Sebor
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=904cf80e-7cd1-3451-f703-e4ea4916ef31@gmail.com \
--to=msebor@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=jason@redhat.com \
/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).