Topic: nested types in anonymous unions
Author: scott douglass <sdouglass@arm.com>
Date: 2000/03/17 Raw View
Hello,
I recently encountered a compiler that refused something like this:
union { struct { int a, b; } c; };
on the grounds that you cannot define types in an anonymous union. And indeed section 9.5 sayeth:
The member-specification of
an anonymous union shall only define non-static data members. [Note:
nested types and functions cannot
be declared within an anonymous union. ]
I think the standard is being overly restrictive here since the case I show above is useful. I think it would be better to change this to:
The member-specification of
an anonymous union shall only define types and non-static
data members. [Note: Any nested types and enumerators
of nested types within an anonymous union will not be visible
(or even nameable) outside the anonymous union. ]
There are also a few more places where the standard says things like "the members of an anonymous union" which would need to become "the (non-static) data members of an anonymous union".
This does mean an implementation would have to be able to generate type_info for these nested types but that doesn't seem any more difficult than nested types in untagged structs which it already has to handle.
But other people may be able to think of more problems. Or they might be happy the way things are.
This doesn't seem serious enough for a Defect Report since the standard is consistent and useable as is (I just have to hoist the structs out of the union and give them tags) -- on the other hand, I don't think there's any other way to get the matter considered. Is there a better way of submitting an Enhancement Request?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]