node (gcc.info)Function Attributes says: `unused' This attribute, attached to a function, means that the function is meant to be possibly unused. GCC will not produce a warning for this function. GNU C++ does not currently support this attribute as definitions without parameters are valid in C++. Does that last sentence make any sense at all? Release: 3.0.1
Fix: Here's a possible rewriting which may be clearer overall: `unused' GCC -Wunused will warn about functions it finds that are not used. Attaching this attribute to a function will disable the warning for that function.
State-Changed-From-To: open->analyzed State-Changed-Why: This still applies. I agree that the last sentence of the attribute description is un-understandable: --------------- @cindex @code{unused} attribute. @item unused This attribute, attached to a function, means that the function is meant to be possibly unused. GCC will not produce a warning for this function. GNU C++ does not currently support this attribute as definitions without parameters are valid in C++. ----------------- What is the supposed meaning of it? Unfortunately, the CVS history does not reach back far enough...
Responsible-Changed-From-To: unassigned->bje Responsible-Changed-Why: I'll take this.
Ben, this has been assigned to you for a few months, any progress?
Subject: Re: __attribute__ ((unused) seems misdocumented "dhazeghi at yahoo dot com" <gcc-bugzilla@gcc.gnu.org> writes: > Ben, this has been assigned to you for a few months, any progress? I guess I picked it off the stack to work on it, but never got started. Feel free to reassign it to anyone interested. Ben
Reassign this one to no one.
The last sentence is supposed to mean "attribute unused is not supported by G++", plus some bogus rationale. Which is false anyway, I think.
I think the last sentence means that c++ supports that definition of agruments can be unamed, other than that the unused is not misdocumented.
Created attachment 5065 [details] a C file with and without unused tags Here's a test case that shows three possible uses of __attribute__((unused)). These are the three uses I can think of; there may be more. The three uses are: - suppress a warning about a static symbol that is never used - suppress a warning about an argument that is never used - suppress a warning about a local symbol that is never used If you compile the same file, but with a .cpp extension to compile as C++, gcc gives an error when we try to attach an __attribute__ to a function argument.
Given that, how is the following wording: @cindex @code{unused} attribute. @item unused This attribute suppresses the warning about a variable or function that is not being used anywhere in its scope.
Actually now with 3.4.0 the part about C++ is wrong because now you can use the attribute in C++. The problem is that the attribute can be put on variables also not just functions.
(In reply to comment #11) > Actually now with 3.4.0 the part about C++ is wrong because now you can use the attribute in > C++. The problem is that the attribute can be put on variables also not just functions. Actually for C the attribute can also be applied to labels! BUT not for C++. The following code (based on the default output from bison 1.875), will compile in C mode, but not in C++ mode:- void fred() { int x; yyerrlab1: __attribute__ ((__unused__)) 1 x = 42; } The intention is to tell the compiler that yyerrlab1: may be unused, but in C++ mode you get the following error:- 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' It also allows its use And even more cunningly it can (or should be) possible to attach it to labels.
(In reply to comment #12) > (In reply to comment #11) Sorry, my example got mangled when I copied it in.... void fred() { int x; yyerrlab1: __attribute__ ((__unused__)) x = 42; }
The reason why it is not allowed in C++ on labels has been stated several times: in C++, a variable declaration can follow a label, so the attribute that you want to attach to the label really goes to the next statement; gcc expects it to be a declaration, and complains if it can't find one. W.
Subject: Re: __attribute__ ((unused) seems misdocumented Does that mean that there is no alternative way of tell gcc, in c++ mode, that the label might not be used? If so, I will raise a bug/enhancement request against bison suggesting they change their usage to be #ifndef __cplusplus or something. Cheers Mark On Tue, 24 Feb 2004, bangerth at dealii dot org wrote: > > ------- Additional Comments From bangerth at dealii dot org 2004-02-24 14:21 ------- > The reason why it is not allowed in C++ on labels has been stated > several times: in C++, a variable declaration can follow a label, > so the attribute that you want to attach to the label really goes > to the next statement; gcc expects it to be a declaration, and > complains if it can't find one. > > W. > >
There indeed doesn't seem to be a way. W.
Isn't this supposed to work: mylabel __attribute__((unused)): Does it work? Maybe it should.
I think it would be sensible if it would. But I checked this morning, and it doesn't. W.
GCC documentation has been changed. __attribute__((unused)) on labels can be used in C++ code since GCC version 4.5.0. This PR should be closed probably.
(In reply to comment #19) > GCC documentation has been changed. __attribute__((unused)) on labels can be > used in C++ code since GCC version 4.5.0. This PR should be closed probably. The less, the merrier. Thanks! (If you get a gcc.gnu.org account, you can do bug management: http://gcc.gnu.org/svnwrite.html#authenticated)