<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - "Protocol *" isn't properly loaded from ObjectiveC module"
href="http://llvm.org/bugs/show_bug.cgi?id=19061">19061</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>"Protocol *" isn't properly loaded from ObjectiveC module
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Modules
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>jordan_rose@apple.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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?</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>