diff options
author | Steve Naroff <snaroff@apple.com> | 2009-03-01 16:12:44 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2009-03-01 16:12:44 +0000 |
commit | 91b0b0cf6b537cbcbca0038c7032f87161a41d31 (patch) | |
tree | 846f280b27db963040c60612f2e344c7d791f7e4 /lib/AST/ASTContext.cpp | |
parent | 0312c0e09c9de480d78607972ac64a88f4e94a33 (diff) |
Fix <rdar://problem/6619539> incompatible pointer types sending 'XCElementSpacer *', expected 'XCElement *' (not handling protocol signatures correctly?).
- Reworked ASTContext::canAssignObjCInterfaces().
- Added ObjCProtocolDecl::lookupProtocolNamed().
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65773 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ASTContext.cpp')
-rw-r--r-- | lib/AST/ASTContext.cpp | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 749655d871..2100a66c38 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -2501,33 +2501,29 @@ bool ASTContext::canAssignObjCInterfaces(const ObjCInterfaceType *LHS, // Finally, we must have two protocol-qualified interfaces. const ObjCQualifiedInterfaceType *LHSP =cast<ObjCQualifiedInterfaceType>(LHS); const ObjCQualifiedInterfaceType *RHSP =cast<ObjCQualifiedInterfaceType>(RHS); - ObjCQualifiedInterfaceType::qual_iterator LHSPI = LHSP->qual_begin(); - ObjCQualifiedInterfaceType::qual_iterator LHSPE = LHSP->qual_end(); - ObjCQualifiedInterfaceType::qual_iterator RHSPI = RHSP->qual_begin(); - ObjCQualifiedInterfaceType::qual_iterator RHSPE = RHSP->qual_end(); - - // All protocols in LHS must have a presence in RHS. Since the protocol lists - // are both sorted alphabetically and have no duplicates, we can scan RHS and - // LHS in a single parallel scan until we run out of elements in LHS. - assert(LHSPI != LHSPE && "Empty LHS protocol list?"); - ObjCProtocolDecl *LHSProto = *LHSPI; - - while (RHSPI != RHSPE) { - ObjCProtocolDecl *RHSProto = *RHSPI++; - // If the RHS has a protocol that the LHS doesn't, ignore it. - if (RHSProto != LHSProto) - continue; - - // Otherwise, the RHS does have this element. - ++LHSPI; - if (LHSPI == LHSPE) - return true; // All protocols in LHS exist in RHS. - - LHSProto = *LHSPI; - } - // If we got here, we didn't find one of the LHS's protocols in the RHS list. - return false; + // All LHS protocols must have a presence on the RHS. + assert(LHSP->qual_begin() != LHSP->qual_end() && "Empty LHS protocol list?"); + + for (ObjCQualifiedInterfaceType::qual_iterator LHSPI = LHSP->qual_begin(), + LHSPE = LHSP->qual_end(); + LHSPI != LHSPE; LHSPI++) { + bool RHSImplementsProtocol = false; + + // If the RHS doesn't implement the protocol on the left, the types + // are incompatible. + for (ObjCQualifiedInterfaceType::qual_iterator RHSPI = RHSP->qual_begin(), + RHSPE = RHSP->qual_end(); + !RHSImplementsProtocol && (RHSPI != RHSPE); RHSPI++) { + if ((*RHSPI)->lookupProtocolNamed((*LHSPI)->getIdentifier())) + RHSImplementsProtocol = true; + } + // FIXME: For better diagnostics, consider passing back the protocol name. + if (!RHSImplementsProtocol) + return false; + } + // The RHS implements all protocols listed on the LHS. + return true; } bool ASTContext::areComparableObjCPointerTypes(QualType LHS, QualType RHS) { |