llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.1k stars 12.01k forks source link

Forward declared protocols + inherited protocol conformance results in protocol conformance warnings #10722

Open llvmbot opened 13 years ago

llvmbot commented 13 years ago
Bugzilla Link 10350
Version unspecified
OS MacOS X
Attachments Test case, compile options detailed in description
Reporter LLVM Bugzilla Contributor

Extended 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' is incompatible with type 'id' inherited from 'Parent' @​property (assign) id 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

llvmbot commented 11 years ago

A test case for allowing use of narrower forward-declared protocols in property declarations