This is the mail archive of the gcc@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]

RFC: Deprecate (a little bit) of C++ attribute syntax


Currently, the C++ front end accepts this syntax:

  int x (3) __attribute__((unused));

Grammatically, in an init-declarator, attributes can come after the
initializer, provided that the initializer is of the parenthesized
form above.  (You cannot write "int x = 3 __attribute__((unused));".)

In my opinion, it is a mistake to allow the attributes to come after
the initializer.  The reason is that "x" is in scope during its own
initializer.  Consider, then, something like this:

  int x (__alignof__(x)) __attribute__((aligned (32)));

In order to get 32 into "x", the evaluation of "__alignof__(x)" would
have to be delayed until after the attributes at the end are handled.
This is complicated, and will be slow to boot.

This is not so much of a problem in the current compiler because the
current compiler is buggy; the code above does not compile, saying:

  test.C:1: error: `x' was not declared in this scope

The new parser does not have this bug, which caused me to think about
the attribute oddity.

There are, of course, a variety of ways to rewrite things so that the
attributes are not after the initializer; you can put them immediately
after "x" for example.  As far as I can tell, this syntax was never
documented.

Therefore, I'm proposing deprecating this syntax in GCC 3.3 and
removing it in GCC 3.4 (with the new parser).  I'm not sure if I can
get the old parser to actually warn about this (it's confused and
thinks the parenthesized initializer is part of the declarator, but
there is then later magic to untangle that!) -- but I will try.

Objections?

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com


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