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

            Bug ID: 100069
           Summary: function redeclaration with noreturn not rejected
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

In [dcl.attr.noreturn] the C++ standard specifies that

  The first declaration of a function shall specify the noreturn attribute if
any declaration of that function specifies the noreturn attribute.

The test case below shows that GCC fails to enforce this constraint for
declarations in different scopes.

$ cat t.C && gcc -O2 -S -Wall -Wextra -Wpedantic t.C
void g ()
{
  void f ();
}

void h ()
{
  [[noreturn]] void f ();
}

void ff ();
[[noreturn]] void ff ();

t.C:12:19: error: function ‘void ff()’ declared ‘[[noreturn]]’ but its first
declaration was not
   12 | [[noreturn]] void ff ();
      |                   ^~
t.C:11:6: note: previous declaration of ‘void ff()’
   11 | void ff ();
      |      ^~


In contrast, Clang issues errors for both redeclarations:

t.C:8:5: error: function declared '[[noreturn]]' after its first declaration
  [[noreturn]] void f ();
    ^
t.C:3:8: note: declaration missing '[[noreturn]]' attribute is here
  void f ();
       ^
t.C:12:3: error: function declared '[[noreturn]]' after its first declaration
[[noreturn]] void ff ();
  ^
t.C:11:6: note: declaration missing '[[noreturn]]' attribute is here
void ff ();
     ^
2 errors generated.

Reply via email to