This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/68188] Ambiguous code gets compiled successfully when class and its namespace have the same name
- From: "rguenth at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 03 Nov 2015 10:37:51 +0000
- Subject: [Bug c++/68188] Ambiguous code gets compiled successfully when class and its namespace have the same name
- Auto-submitted: auto-generated
- References: <bug-68188-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68188
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |accepts-invalid,
| |rejects-valid
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
So the actual bug is that the following is rejected:
namespace Foo
{
class Foo
{
public:
static int x;
};
int Foo::x;
}
int main()
{
using namespace Foo;
Foo::x;
return 0;
}
which means that GCC does not consider the used namespace Foo when seeing
the qualified name 'Foo::x' (it finds Foo::Foo:x just fine).
When changing the above to
namespace Foo
{
namespace Foo
{
int x;
}
}
int main()
{
using namespace Foo;
Foo::x;
return 0;
}
then we get
t.C: In function âint main()â:
t.C:11:3: error: reference to âFooâ is ambiguous
Foo::x;
^
t.C:2:1: note: candidates are: namespace Foo { }
{
^
t.C:4:5: note: namespace Foo::Foo { }
{
^
which means that the actual ambiguity is on 'Foo' (also with your own
testcase)?