This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [gcc-in-cxx] Permit __attribute__ ((unused)) on labels in C++
Ian Lance Taylor wrote:
"Joseph S. Myers" <joseph@codesourcery.com> writes:
On Tue, 10 Feb 2009, Ian Lance Taylor wrote:
The generated file insn-recog.c contains a lot of unused labels. These
are marked with ATTRIBUTE_UNUSED_LABEL. That attribute is not supported
by current g++, causing a -Werror failure when building with C++. This
patch adds support for __attribute__ ((unused)) on labels to the C++
compiler. Committed to gcc-in-cxx branch.
You need to update extend.texi where it says "GNU C++ does not permit such
placement of attribute lists, as it is permissible for a declaration,
which could begin with an attribute list, to be labelled in C++.". What
do you do if the label in question is followed by a declaration? And is
this consistent with the attributes support in C++0x?
I'll worry about the docs, and test cases, when I propose the patch for
mainline. But I didn't realize that there was an ambiguity here. That
does seem to be a problem. This test case:
void quux() { a: __attribute__ ((unused)) int i; }
gives this warning in mainline:
foo.cc:1: warning: label âaâ defined but not used
and this warning in gcc-in-cxx branch:
foo.cc:1: warning: unused variable âiâ
This seems unfortunate. We could simply declare by fiat that attributes
following a label are associated with the label, although that it is
conceivable that that would change the behaviour of existing code.
An alternative would be to accept another syntax, with the attribute
before the colon, e.g.
void quuxa() { a __attribute__ ((unused)): int i; }
and always consider that in
void quuxb() { a: __attribute__ ((unused)) int i; }
the unused attribute is associated with the i declaration (both in C,
C++ and any other C-like language if needed).
Besides, I'm not very familiar with attributes (I really use them very
rarely), and my intuitive parsing of the quuxb function was the same
as G++ did.
Regards.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***