This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR 53528 c++/ C++11 Generalized Attribute support


On 08/10/2012 04:04 PM, Dodji Seketeli wrote:
In cp_parser_decl_specifier_seq, I first tried to apply the c++11
attribute to the (already constructed) type it follows, like what you
suggest.  But then I am getting the warning:

warning: ignoring attributes applied to 'A' after definition

issued by build_type_attribute_qual_variant when called by
decl_attribute.  Basically, this is because we are not allowed to
build a distinct copy of a class type.

Right.


Then I figured maybe I could:

  - do what you suggest for non-tagged types.
  - for tagged types apply the attribute to the decl.  The aligned
    attribute in particular can be applied to the decl; that's a
    practical workaround way to comply with the requirement to apply
    the attribute to the type only for that declaration.

Or we could just require people to put the attribute in the right place (or one of the right places) if they want it to apply to the decl. That is, either at the beginning of the declaration statement or after the declarator-id. Again, I don't think we want to extend the flexible binding of GNU attributes to C++11 attributes.


+typedef union { int i; } U [[gnu::transparent_union]];

For the same reason, this should also be rejected; the testcase should put the attribute before the opening brace. We accept this with GNU-style attributes for backward compatibility, but there's no reason to propagate that lossage into the new syntax.

Syntactically, why can't we say that the attribute applies to the typedef? My understanding is that this is syntactically allowed by the noptr-declarator production.

Yes, syntactically it's fine. But semantically it doesn't make sense, because the attribute only applies to types, not declarations. Even if we looked through typedefs, it would be applying an attribute to a class after its definition was complete.


If you want the attribute to be rejected for this particular kind of
cases, how would you like to do it?

It should be rejected because it's applying a type attribute to a declaration.


For unused though, I am not sure how to do that in an appropriate
manner.  An idea?

What does it mean to say that int is unused? It seems meaningless to me.


Jason


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]