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. "
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
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.
*** This bug has been marked as a duplicate of 11613 ***