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

            Bug ID: 118381
           Summary: GCC ignores missing 'noexcept' specifier for friend
                    declaration
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wangbopku15 at gmail dot com
  Target Milestone: ---

GCC does not generate errors on the following code:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

struct S
{  
  void f()
    noexcept{}
};


class C
{
  friend void S::f();
};


int main()
{
  C ci;
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As a comparison, clang rejects it with:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<source>:10:18: error: 'f' is missing exception specification 'noexcept'
   10 |   friend void S::f();
      |                  ^  
      |                      noexcept
<source>:3:8: note: previous declaration is here
    3 |   void f()
      |        ^
1 error generated.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

EDG with:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

"<source>", line 10: error: allowing all exceptions is incompatible with
previous function "S::f" (declared at line 3)
    friend void S::f();
                      ^

"<source>", line 16: warning: variable "ci" was declared but never referenced
    C ci;
      ^

1 error detected in the compilation of "<source>".

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

See https://godbolt.org/z/T9q7Pfa9q
  • [Bug c++/118381] New: GCC ignore... wangbopku15 at gmail dot com via Gcc-bugs

Reply via email to