[Bug objc/45895] New: -Wunused-but-set-variable complains for almost all Objective-C objects

nicola at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Oct 5 12:48:00 GMT 2010


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45895

           Summary: -Wunused-but-set-variable complains for almost all
                    Objective-C objects
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: objc
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: nicola@gcc.gnu.org


It seems that -Wunused-but-set-variable complains any time an Objective-C
object variable is set, and only used to invoke methods.  This is incorrect;
when a variable is used to invoke a method, it is used. :-)

(hence, compiling any Objective-C with -Wall generates lots of wrong warnings).

Here is a testcase --

#include <objc/objc.h>
#include <objc/Object.h>

int main (void)
{
  id o = nil;

  [o hash];

  return 0;
}

Here are what happens when you compile:

[nicola@lampone ~]$ gcc -Wall bug.m -lobjc -c
bug.m: In function ‘main’:
bug.m:6:6: warning: variable ‘o’ set but not used [-Wunused-but-set-variable]
[nicola@lampone ~]$ 

The warning is obviously incorrect because 'o' *is* used.  This is on a
i686-pc-linux-gnu.

Thanks



More information about the Gcc-bugs mailing list