RFR: 8313396: Portable implementation of FORBID_C_FUNCTION and ALLOW_C_FUNCTION

Kim Barrett kbarrett at openjdk.org
Mon Dec 30 07:53:36 UTC 2024


On Mon, 30 Dec 2024 07:43:01 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> [[gnu::noreturn]] is equal to __attribute__((noreturn)), I just referred to it as its scoped attribute form to make it clear that I wasn't talking about the Standard noreturn. There is funnily enough no documentation on how gcc treats them differently, I only learnt that it does while reading through gcc's source code one day
>> 
>> 
>> /* We used to treat C++11 noreturn attribute as equivalent to GNU's,
>> 	 but no longer: we have to be able to tell [[noreturn]] and
>> 	 __attribute__((noreturn)) apart.
>> 	 Similarly for C++14 deprecated attribute, we need to emit extra
>> 	 diagnostics for [[deprecated]] compared to [[gnu::deprecated]].  */
>>       /* C++17 fallthrough attribute is equivalent to GNU's.  */
>
> gcc does treat [[noreturn]] differently from [[gnu::noreturn]] /
> attribute((noreturn)) when there is a preceding declaration that doesn't have
> either kind of attribute.  Compile this:
> 
> void frob(int);
> //__attribute__((__noreturn__)) void frob(int);
> //[[gnu::noreturn]] void frob(int);
> [[noreturn]] void frob(int);
> 
> and you'll get an error:
> 
> error: function 'void frob(int)' declared '[[noreturn]]' but its first declaration was not
> 
> But uncomment either of the gnu-specific attributes and the error goes away.
> 
> C++14 7.6.3 "Noreturn attribute" says "The first declaration of a function
> shall specify the noreturn attribute if any declaration of that function
> specifies the noreturn attribute."
> 
> So without the declarations with gcc-specific attributes it errors, and that's
> fine. The gcc-specific attributes never complained in that situation, and
> continue to not complain, for backward compatibility. But other than that
> error checking difference, the gcc-specific attributes seem to be treated as
> equivalent to the standard attribute.

The difference between [[deprecated]] and [[gnu::deprecated]] is discussed here:
https://gcc.gnu.org/git/?p=gcc.git;a=commit;f=gcc/cp/parser.cc;h=cd647514a539943ade6461efbf056a7c3f4305c6
TL;DR - [[gnu::deprecated]] is allowed in more places than [[deprecated]].

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/22890#discussion_r1899346761


More information about the graal-dev mailing list