https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118236
Bug ID: 118236
Summary: gcc does not realize ambiguous friend class
declaration with multiple using namespace
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: ---
Consider the following code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
namespace N1 { struct A { }; }
namespace N2 { struct A { }; }
using namespace N1;
using namespace N2;
struct B
{
friend class A;
};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This should be invalid as the 'friend class A' declaration should be both
'N1::A' and 'N2::A' aaccording to the 'using namespace' statements above,
leading to ambiguity.
Both clang and MSVC reject the code. The diagnostic of clang says that:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:8:17: error: reference to 'A' is ambiguous
8 | friend class A;
| ^
<source>:1:23: note: candidate found by name lookup is 'N1::A'
1 | namespace N1 { struct A { }; }
| ^
<source>:2:23: note: candidate found by name lookup is 'N2::A'
2 | namespace N2 { struct A { }; }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Please see https://godbolt.org/z/6Eev3xfbv