RFR: 8313396: Portable implementation of FORBID_C_FUNCTION and ALLOW_C_FUNCTION

Kim Barrett kbarrett at openjdk.org
Mon Dec 30 07:45:33 UTC 2024


On Mon, 30 Dec 2024 05:26:36 GMT, Julian Waters <jwaters at openjdk.org> wrote:

>> I don't know what `[[gnu::noreturn]]` has to do with this?  And in what way does gcc treat them differently?
>
> [[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.

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

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


More information about the graal-dev mailing list