This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Attributes on structs
- From: Jason Merrill <jason at redhat dot com>
- To: GCC <gcc at gcc dot gnu dot org>
- Date: Wed, 07 Nov 2007 17:46:21 -0500
- Subject: Attributes on structs
There are several outstanding bugs (29436, 28560, 28834, possibly
others) having to do with applying attributes to uses of structs in
typedefs or other places other than the point of definition. The
problem with doing this is that the attribute code makes a new
TYPE_MAIN_VARIANT, so we basically get a new type which shares the name
and members of the original type. This causes trouble for the C++ type
system and other parts of the compiler that assume that all variants of
a class with a particular name have the same TYPE_MAIN_VARIANT.
I notice that the GCC manual only says that type attributes can be
applied in a typedef or type definition, but in fact the compiler allows
them to be applied anywhere.
Sometimes the attributes are intended to create new types (vector), but
usually not; the modified types are intended to work like the base type.
Sometimes the attribute has important implications for code generation
(aligned), sometimes it doesn't (unused).
For the cases that have important implications for code generation, we
need the TYPE_MAIN_VARIANT trick because a lot of places in the compiler
assume that they can just take TYPE_MAIN_VARIANT to strip cv-quals, and
we don't want that to discard important attributes.
One solution to this issue would be to simply disallow attributes on
structs after the definition. Failing that, we need to define how they
interact with the type system. Opinions?
Jason