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

            Bug ID: 122650
           Summary: Redeclarations of function which add noreturn
                    attributes should be diagnosed
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: luigighiron at gmail dot com
  Target Milestone: ---

The following code is incorrectly accepted by GCC:

int x(),x[[noreturn]]();
int main(){}

> The first declaration of a function shall specify the noreturn attribute if
> any declaration of that function specifies the noreturn attribute. If a
> function is declared with the noreturn attribute in one translation unit and
> the same function is declared without the noreturn attribute in another
> translation unit, the behavior is undefined.
Section 6.7.13.7 "The noreturn and _Noreturn attributes" Paragraph 3 ISO/IEC
9899:2024

The first declaration of x doesn't specify noreturn and at least one other
redeclaration does, so this is invalid. GCC correctly diagnoses this in C++
mode. Also, the _Noreturn function specifier doesn't appear to have any wording
to this effect so this restriction shouldn't extend to that.

Clang appears to have the same issue as GCC, and correctly diagnoses in C++
mode too.

Reply via email to