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

            Bug ID: 118242
           Summary: GCC fails to identify ambiguous member name in friend
                    declaration in multiple inheritance
           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: ---

The following invalid code is now accepted by GCC:

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

struct M1 {
    struct I{ };
};

struct M2 {
    struct I{};

};

struct J : public M2::I,public M1::I{     
    friend class I;
};

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

The declaration of 'friend class I' inside 'struct J' should be erroneous, as
this scope contains both 'M2::I' and 'M1::I' according to the multiple
inheritance and merely using 'I' is ambiguous.

Clang rejects it by complaining that:

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

<source>:11:18: error: member 'I' found in multiple base classes of different
types
   11 |     friend class I;
      |                  ^
<source>:6:12: note: member type 'M2::I' found by ambiguous name lookup
    6 |     struct I{};
      |            ^
<source>:2:12: note: member type 'M1::I' found by ambiguous name lookup
    2 |     struct I{ };
      |            ^
1 error generated.

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

MSVC and EDG also reject it. Please see https://godbolt.org/z/crj9P9K63

Reply via email to