[LLVMbugs] [Bug 19061] New: "Protocol *" isn't properly loaded from ObjectiveC module
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed Mar 5 18:48:52 PST 2014
http://llvm.org/bugs/show_bug.cgi?id=19061
Bug ID: 19061
Summary: "Protocol *" isn't properly loaded from ObjectiveC
module
Product: clang
Version: trunk
Hardware: PC
OS: MacOS X
Status: NEW
Severity: normal
Priority: P
Component: Modules
Assignee: unassignedclangbugs at nondot.org
Reporter: jordan_rose at apple.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
Objective-C has a class named "Protocol" which represents the runtime metadata
about a Protocol. It is defined in <objc/Protocol.h>, which on OS X 10.9 is the
ObjectiveC.Protocol module.
The Protocol class is special because it can be generated by the @protocol
expression:
Protocol *codingProto = @protocol(NSCoding);
if ([obj conformsToProtocol:codingProto]) { /*...*/ }
The class is thus forward-declared in every translation unit as one of the
predefined types, roughly as "@class Protocol;".
With all of this set up, I can perform a lookup for "Protocol" and get back an
ObjCInterfaceDecl for this forward declaration. If I have imported the
ObjectiveC module and ask for the definition, I get it as expected. The trouble
comes when I import another module that #imports some (but not all) of the
headers from the ObjectiveC module. It is easiest to demonstrate with a fake
subclass of Protocol, something that requires a definition. (Please ignore the
fact that no one would actually do this; the real client is a tool built on
Clang.)
This program is correctly accepted by Clang:
@import ObjectiveC;
@interface Foo : Protocol
@end
This program is correctly rejected by Clang with a nice diagnostic:
@import Foundation;
@interface Foo : Protocol
@end
<stdin>:3:18: error: definition of 'Protocol' must be imported from module
'ObjectiveC.Protocol' before it is required
@interface Foo : Protocol
^
But this program gets the /wrong/ diagnostic:
@import AppKit;
@interface Foo : Protocol
@end
<stdin>:3:18: error: attempting to use the forward class 'Protocol' as
superclass
of 'Foo'
@interface Foo : Protocol
~~~~~~~~~~~~~~ ^
After tracing through the code in ASTReader::updateOutOfDateIdentifier, it
looks like we search the AppKit module for the name "Protocol", find a match,
and stop the search there. ModuleManager::visit then notes that we found a
match, and therefore /shouldn't search anything visible via AppKit/.
I haven't gotten any further than that, but why does Foundation work, and what
can we do to fix this?
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140306/bc03738b/attachment.html>
More information about the llvm-bugs
mailing list