public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Martin Sebor <msebor@gmail.com>
To: Marek Polacek <polacek@redhat.com>, Jakub Jelinek <jakub@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>, Jason Merrill <jason@redhat.com>
Subject: Re: C++ PATCH for c++/60364 - noreturn after first decl not diagnosed (v2)
Date: Mon, 17 Jun 2019 15:02:00 -0000	[thread overview]
Message-ID: <bec14aa9-efce-d8b5-eda8-baf3615b04e3@gmail.com> (raw)
In-Reply-To: <20190616161037.GK5989@redhat.com>

On 6/16/19 10:10 AM, Marek Polacek wrote:
> On Sat, Jun 15, 2019 at 10:39:13AM -0400, Marek Polacek wrote:
>> On Sat, Jun 15, 2019 at 04:33:26PM +0200, Jakub Jelinek wrote:
>>> On Sat, Jun 15, 2019 at 10:29:17AM -0400, Marek Polacek wrote:
>>>> [dcl.attr.noreturn] says "The first declaration of a function shall specify the
>>>> noreturn attribute if any declaration of that function specifies the noreturn
>>>> attribute" meaning that we should diagnose
>>>>
>>>>    void func ();
>>>>    void func [[noreturn]] ();
>>>>
>>>> but we do not.  I'd been meaning to issue a hard error for [[noreturn]] and
>>>> only a warning for __attribute__((noreturn)) but then I found out that we
>>>> treat [[noreturn]] exactly as the GNU attribute, and so cxx11_attribute_p
>>>> returns false for it, so I decided to make it a pedwarn for all the cases.
>>>> A pedwarn counts as a diagnostic, so we'd be conforming still.
>>>>
>>>> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>>>
>>> IMHO we should treat __attribute__((noreturn)) as before without any
>>> warnings, just [[noreturn]] that way.  There is nothing wrong on declaring
>>> it just on second or following declaration, it is an optimization attribute.
>>
>> That's a complication then; currently [[noreturn]], [[gnu::noreturn]], and
>> __attribute__((noreturn)) are not distinguishable.  :(
>>
>> Guess I will really have to make the changes to treat [[noreturn]] similarly
>> to e.g. [[nodiscard]], so that cxx11_attribute_p works.
> 
> Thus.  Changes I've made:
> * don't treat [[noreturn]] as an equivalent to __attribute__((noreturn));
> * for that I had to adjust decl_attributes, it wasn't preserving the
>    C++11 form (a list in another list); fix shadowing while at it;
> * the above turned up two spots that were wrongly accessing TREE_PURPOSE
>    directly instead of using get_attribute_name;
> * give error only for [[noreturn]] but not for __attribute__((noreturn))
>    or [[gnu::noreturn]].
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
> 
> 2019-06-16  Marek Polacek  <polacek@redhat.com>
> 
> 	PR c++/60364 - noreturn after first decl not diagnosed.
> 	* attribs.c (get_attribute_namespace): No longer static.
> 	(decl_attributes): Avoid shadowing.  Preserve the C++11 form for C++11
> 	attributes.
> 	* attribs.h (get_attribute_namespace): Declare.
> 	* tree-inline.c (function_attribute_inlinable_p): Use
> 	get_attribute_name.
> 
> 	* c-attribs.c (handle_noreturn_attribute): No longer static.
> 	* c-common.h (handle_noreturn_attribute): Declare.
> 	* c-format.c (check_function_format): Use get_attribute_name.
> 
> 	* decl.c (duplicate_decls): Give an error when a function is
> 	declared [[noreturn]] after its first declaration.
> 	* parser.c (cp_parser_std_attribute): Don't treat C++11 noreturn
> 	attribute as equivalent to GNU's.
> 	* tree.c (std_attribute_table): Add noreturn.
> 
> 	* g++.dg/warn/noreturn-8.C: New test.
...
> diff --git gcc/cp/tree.c gcc/cp/tree.c
> index cd021b7f594..bb695e14e73 100644
> --- gcc/cp/tree.c
> +++ gcc/cp/tree.c
> @@ -4453,6 +4453,8 @@ const struct attribute_spec std_attribute_table[] =
>       handle_likeliness_attribute, attr_cold_hot_exclusions },
>     { "unlikely", 0, 0, false, false, false, false,
>       handle_likeliness_attribute, attr_cold_hot_exclusions },
> +  { "noreturn", 0, 0, true, false, false, false,
> +    handle_noreturn_attribute, NULL },
                                   ^^^^

The GNU attribute is made mutually exclusive with a bunch of other
attributes (e.g., malloc or warn_unused_result) by setting the last
member to the array of exclusive attribute.  Does the change preserve
this relationship some other way?

Martin

  parent reply	other threads:[~2019-06-17 15:02 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-15 14:29 C++ PATCH for c++/60364 - noreturn after first decl not diagnosed Marek Polacek
2019-06-15 14:33 ` Jakub Jelinek
2019-06-15 14:39   ` Marek Polacek
2019-06-16 16:10     ` C++ PATCH for c++/60364 - noreturn after first decl not diagnosed (v2) Marek Polacek
2019-06-16 16:19       ` Jakub Jelinek
2019-06-16 16:37         ` C++ PATCH for c++/60364 - noreturn after first decl not diagnosed (v3) Marek Polacek
2019-06-17 15:48           ` Jakub Jelinek
2019-06-17 18:15             ` Marek Polacek
2019-06-17 15:02       ` Martin Sebor [this message]
2019-06-17 18:11         ` C++ PATCH for c++/60364 - noreturn after first decl not diagnosed (v2) Marek Polacek
2019-06-19 19:31           ` Jeff Law
2019-06-20 16:44           ` Joseph Myers
2019-06-20 16:49             ` Marek Polacek
2019-06-20 17:08               ` Joseph Myers
2019-06-20 17:14                 ` Marek Polacek
2019-06-20 17:57               ` Jakub Jelinek
2019-06-20 19:12                 ` Marek Polacek

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=bec14aa9-efce-d8b5-eda8-baf3615b04e3@gmail.com \
    --to=msebor@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jason@redhat.com \
    --cc=polacek@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).