Bug 14273 - __attribute__ ((__unused__)) fails when attached to a label in c++
Summary: __attribute__ ((__unused__)) fails when attached to a label in c++
Status: RESOLVED DUPLICATE of bug 11613
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-02-24 13:51 UTC by msp
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: sparc-sun-solaris2.8
Target: sparc-sun-solaris2.8
Build: sparc-sun-solaris2.8
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description msp 2004-02-24 13:51:28 UTC
Bison 1.875 generates code which contains something like this:-

yyerrlab1:
 __attribute__ ((__unused__))

Now this works for C compilation (ie. tells the compiler yyerrlab1 might not be
used, so stops the compiler generating a warning), but fails to compile for C++.

The following test code is similar to what bison does. It compiles for C, but
not for C++:-

void fred()
{
   int x;
   
yyerrlab1:
 __attribute__ ((__unused__))

 x = 42;
 
}
p.cc: In function `void fred()':
p.cc:8: error: ISO C++ forbids declaration of `x' with no type
p.cc:8: error: redeclaration of `int x'
p.cc:3: error: `int x' previously declared here
p.cc:8: error: declaration of `int x'
p.cc:3: error: conflicts with previous declaration `int x'


The documentation "Attribute Syntax" info node appears to say this should work:-

"   An attribute specifier list may appear after the colon following a
label, other than a `case' or `default' label.  The only attribute it
makes sense to use after a label is `unused'.  This feature is intended
for code generated by programs which contains labels that may be unused
but which is compiled with `-Wall'.  It would not normally be
appropriate to use in it human-written code, though it could be useful
in cases where the code that jumps to the label is contained within an
`#ifdef' conditional.
"
Comment 1 msp 2004-02-24 14:02:24 UTC
After some searching I have established this has been raised before under bugid
11613. That bug has been marked FIXED, though as far as I can see it was really
rejected on the grounds that it can't be fixed.

BUT -

Is there an alternative syntax which will work for C++????

If so I can raise a bug/patch against bison so its parsers will compile in C++ mode.

Has the documentation been updated to reflect this limitation. The original
documentation was far from clear.

Cheers
Mark
Comment 2 msp 2004-02-24 14:09:58 UTC
nb. I have also found a comment on the mailing lists stating that

"
  you can say
	label __attribute__((unused)):
  in both gcc and g++
"

BUT that fails to compile for me using g++ 3.3.3 in either C or C++ mode.
Comment 3 msp 2004-02-24 17:04:33 UTC

*** This bug has been marked as a duplicate of 11613 ***