https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108796

            Bug ID: 108796
           Summary: GCC 13 accepts [[noreturn]] attribute without -std=c2x
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sam at gentoo dot org
  Target Milestone: ---

Created attachment 54462
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54462&action=edit
foo.i

GCC 13 (13.0.1 20230212) seems to accept [[noreturn]] as an attribute even when
not in C2x mode. This leads to a build failure with sudo-1.9.13
(https://github.com/sudo-project/sudo/issues/239) since
https://github.com/sudo-project/sudo/commit/e707ffe58b3ccfe5c72f54c38eac1d7069d5021e.

Clang 16.0.0_rc2 does not accept it unless passing -std=c2x.

Is this intentional or not? Thanks.

foo.c:
```
#include <stdlib.h>

[[noreturn]] void foo(void) {
        abort();
}

int main() {
        foo();
}
```

```
$ gcc-13 --version
gcc-13 (Gentoo Hardened 13.0.1_pre20230212 p8) 13.0.1 20230212 (experimental)
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc-13 -std=c2x -O2 /tmp/foo.c # fine
$ gcc-13 -std=c99 -O2 /tmp/foo.c # fine
$ gcc-13 -O2 /tmp/foo.c -o /tmp/foo # fine

$ clang-16 --version
clang version 16.0.0 # actually 16.0.0_rc2
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/16/bin
Configuration file: /etc/clang/clang.cfg

$ clang-16 -O2 /tmp/foo.c -o /tmp/foo
/tmp/foo.c:3:2: error: expected expression
[[noreturn]] void foo(void) {
 ^
/tmp/foo.c:3:14: error: expected identifier or '('
[[noreturn]] void foo(void) {
             ^
/tmp/foo.c:8:2: error: call to undeclared function 'foo'; ISO C99 and later do
not support implicit function declarations [-Wimplicit-function-declaration]
        foo();
        ^
3 errors generated.

$ clang-16 -std=c2x -O2 /tmp/foo.c -o /tmp/foo # fine
```

Reply via email to