[Bug objc/48539] New: Missing warning when messaging a forward-declared class

nicola at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Apr 10 11:10:00 GMT 2011


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

           Summary: Missing warning when messaging a forward-declared
                    class
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: objc
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: nicola@gcc.gnu.org


The following testcase compiles with no warnings on GCC 4.7.0 20110326:

#include <objc/objc.h>

@class A;

@interface B
{
  id isa;
}
+ (void) doSomething;
@end

void test (void)
{
  [A doSomething];
}

While clang produces a hard error:

z.m:14:4: warning: receiver 'A' is a forward class and corresponding @interface
may not exist
  [A doSomething];
   ^
z.m:9:1: note: method 'doSomething' is used for the forward class
+ (void) doSomething;
^
1 warning generated.

In this case, the behaviour of clang seems better.  @class is really meant to 
resolve recursive declarations; it should always be followed by the 
corresponding @interface, particularly if you are going to message the class or 
objects of the class.

I would say that GCC should produce at least a warning in this case!

There's also the issue of whether the following testcase should also produce
a warning:

#include <objc/objc.h>

@class A;

@interface B
{
  id isa;
}
- (void) doSomething;
@end

void test (A *x)
{
  [x doSomething];
}

This is slightly different in that it is an instance message, as opposed to
a class message.  Neither GCC nor clang produce any warning or error here, but 
it sounds like a warning similar to the one above would be very appropriate.

Thanks



More information about the Gcc-bugs mailing list