This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/46206] New: using typedef-name error with typedef name hiding struct name
- From: "nathan.keynes at oracle dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 28 Oct 2010 01:58:31 +0000
- Subject: [Bug c++/46206] New: using typedef-name error with typedef name hiding struct name
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46206
Summary: using typedef-name error with typedef name hiding
struct name
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: nathan.keynes@oracle.com
G++ rejects the following code:
class Foo
{
bool a, b, c, d;
typedef struct Bar { } Bar;
virtual void foo(void) {
struct Bar bar;
}
};
example.cc: In member function âvirtual void Foo::foo()â:
example.cc:6: error: using typedef-name âFoo::Barâ after âstructâ
example.cc:4: error: âFoo::Barâ has a previous declaration here
example.cc:6: error: invalid type in declaration before â;â token
but accepts many similar examples, including:
class Foo
{
bool a, b, c;
typedef struct Bar { } Bar;
virtual void foo(void) {
struct Bar bar;
}
};
This behaviour is reproducible on x86_64-redhat-linux (4.1.2 and 4.4.0) and
i386-pc-solaris2.11 (4.2.4, 4.3.4 and 4.5.1)
I'm uncertain if this is strictly legal or not per the standard, but it doesn't
seem to make sense to accept one of these cases but not the other.