Bug 11613 - attribute unused after label causes error with g++
Summary: attribute unused after label causes error with g++
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P2 normal
Target Milestone: 3.4.0
Assignee: Nathan Sidwell
URL:
Keywords:
: 14273 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-07-21 10:00 UTC by Juergen "George" Sawinski
Modified: 2004-02-24 17:04 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2003-07-21 14:33:25


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Juergen "George" Sawinski 2003-07-21 10:00:03 UTC
The attribute "unused" after a jump label is not understood
by the C++ compiler.

The following simple test program compiles fine with gcc, 
while g++ fails with error:

int main() { 
unused_label: __attribute__((unused))
return 0;
}


Compiler versions tested: 2.95.3, 3.2.3, 3.3
Comment 1 Wolfgang Bangerth 2003-07-21 14:27:51 UTC
I can confirm this. However, I did not find a place in the manual that
states that it is allowed to use an attribute on a label (in particular,
the idea of putting the attribute _after_ the colon seems exceedingly
ugly to me). Can you point me to a relevant statement in the manual?
If there is none, then this would be a bug in the C front end to
grok such a thing.

Thanks
  Wolfgang
Comment 2 Andrew Pinski 2003-07-21 14:33:23 UTC
From <http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html>:
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.

Also from that page:
Because of infelicities in the grammar for attributes, some forms described here may not be 
successfully parsed in all cases
I do not know if this should be acceptable in c++.
Comment 3 Wolfgang Bangerth 2003-07-21 15:01:44 UTC
Thanks Andrew. My personal opinion is that the association of language lawyers
should throughly enjail the person who invented this syntax, and should bar him
from ever again designing language extensions. Oh well...

W.
Comment 4 Nathan Sidwell 2003-07-23 17:17:38 UTC
label: __attribute__ ((whatever))
cannot be well formed g++, because,
this is allowed
    __attribute__ ((unused)) int i;
and so is
    label:  int i;
so what does
    label: __attribute__ ((unused)) int i;
mean?
Comment 5 Nathan Sidwell 2003-07-25 10:54:04 UTC
It's a feature!
2003-07-25  Nathan Sidwell  <nathan@codesourcery.com>

	* doc/extend.texi (Function Attributes): GNU C++ does now allow
	unused parameter decls.
	(Attribute Syntax): GNU C++ does not allow label attributes to be
	after the ':'.
Comment 6 msp 2004-02-24 17:04:35 UTC
*** Bug 14273 has been marked as a duplicate of this bug. ***