[LLVMbugs] [Bug 10350] New: Forward declared protocols + inherited protocol conformance results in protocol conformance warnings

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jul 13 02:38:20 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=10350

           Summary: Forward declared protocols + inherited protocol
                    conformance results in protocol conformance warnings
           Product: clang
           Version: unspecified
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: keith at realmacsoftware.com
                CC: llvmbugs at cs.uiuc.edu


Created an attachment (id=6879)
 --> (http://llvm.org/bugs/attachment.cgi?id=6879)
Test case, compile options detailed in description

Summary:

I make heavy use of protocols and inheritance in one of my projects. My
subclasses often define a more specific delegate protocol than their
superclass, and make their own delegate protocol conform to the protocols of
the superclass' delegate.

When a project compiled with clang imports one of these header chains, the
compiler complains that the declaration of the subclass' delegate property is
incompatible with the superclass' declaration.

I have noted that this only occurs when the protocols are forward declared
using @protocol, and later defined. I like to forward declare my @protocols and
define them after my @interface declaration.


Example Warning Given:

warning: property type
'id<AFNetworkTransportControlDelegate,AFNetworkTransportDataDelegate>' is
incompatible with type
'id<AFNetworkConnectionLayerControlDelegate,AFNetworkConnectionLayerDataDelegate>'
inherited from 'AFNetworkConnectionLayer' [3]


Expected Results:

Don't warn about property type incompatibilities when basing the warning on a
forward declared @protocol, the compiler should read ahead to the @protocol
definition before issuing a warning.


Workaround:

Define the @protocol before the class that uses the declaration in it's
property list, using @class to forward declare the class if necessary.


Example Project:

Attached is an archive with two files.


To demonstrate the warning illustrated above, compile with no additional
defines:

`clang clang_protocol_conformance.m -framework Foundation`

and receive the following warning:

clang_protocol_conformance.m:19:35: warning: property type 'id<ProtocolB>' is
incompatible with type 'id<ProtocolA>' inherited from 'Parent'
@property (assign) id <ProtocolB> delegate;
                                  ^
1 warning generated.


To workaround the problem, define RM_FORWARD_DEFINE_PROTOCOLS, which moves the
#import above the @interface declarations, and fixes the warnings.

Compile with:

`clang clang_protocol_conformance.m -framework Foundation
-DRM_FORWARD_DEFINE_PROTOCOLS`

and no warnings are generated.


Clang Version:

Apple clang version 2.1 (tags/Apple/clang-163.7.1) (based on LLVM 3.0svn)
Target: x86_64-apple-darwin11.0.0
Thread model: posix

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list