This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Anonymous structs with duplicate members within unions
- From: "Steven L. Zook" <SLZook at Qualstar dot com>
- To: <gcc at gcc dot gnu dot org>
- Date: Tue, 18 Jan 2005 13:15:07 -0800
- Subject: Anonymous structs with duplicate members within unions
Consider these declarations:
union uFred { struct { unsigned char A;
unsigned B;
};
struct { unsigned char C;
long D;
};
};
union uDerf { struct { unsigned char A;
unsigned B;
};
struct { unsigned char A;
long D;
};
};
When compiled (using m68k-elf both 3.3.3 and 3.4.2) as C, it gives no
errors or warnings. When compiled as C++, I get:
testpp.cpp:11: error: declaration of `unsigned char uDerf::<anonymous
struct>::A'
testpp.cpp:8: error: conflicts with previous declaration `unsigned char
uDerf::<anonymous struct>::A'
I've looked through the C and C++ specs (I'm a novice on interpreting
these however) but I can't find a specific prohibition or permission on
this issue. I see in the GCC manual that there is a C language extension
covering the uFred case but no C++ extension expressed or implied (even
though it works). I also found
http://gcc.gnu.org/ml/gcc/2004-06/msg00158.html which touches on the
issue but doesn't cover the exact case above and, in fact, is
complaining that a case similar to uFred isn't supported. I found
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=4784 which also speaks to a
set of cases slightly different than above.
Note that the now ancient Microsoft C++ compiler (MSVC v8.00c)
specifically supported uDerf, in both C and C++, as a Microsoft-specific
extension (in fact, they support any name collisions provided the type,
bit size, and offset of the duplicate members match).
Given that the uFred case works in C and C++, and uDerf works in C,
should uDerf work in C++?
This is actually two questions: "should" meaning "is it a bug that it
doesn't?" and "should" meaning "is it a desirable feature/extension?".
I am presuming that the first answer is no (it's not a bug).