diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2008-06-04 19:00:03 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2008-06-04 19:00:03 +0000 |
commit | 6e59392e4bbd56cbfda9aaba9632a9701803677d (patch) | |
tree | 21ca549c6bd7a07e402b2879d04cd4683fdbe1fb /clang/lib/Sema/SemaExprObjC.cpp | |
parent | 61c7f2a633e48d742d7d8548644499f3f09966fb (diff) | |
download | bcm5719-llvm-6e59392e4bbd56cbfda9aaba9632a9701803677d.tar.gz bcm5719-llvm-6e59392e4bbd56cbfda9aaba9632a9701803677d.zip |
Fix a gcc compatibility issue which allows more protocol-qualified id on RHS to be
assigned to less protocol qualified object on LHS.
llvm-svn: 51956
Diffstat (limited to 'clang/lib/Sema/SemaExprObjC.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExprObjC.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index c9cfc92f4d6..108ff3c21e0 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/lib/Sema/SemaExprObjC.cpp @@ -327,13 +327,21 @@ static bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto, /// lookupCategory is true). static bool ClassImplementsProtocol(ObjCProtocolDecl *lProto, ObjCInterfaceDecl *IDecl, - bool lookupCategory) { + bool lookupCategory, + bool RHSIsQualifiedID = false) { // 1st, look up the class. ObjCProtocolDecl **protoList = IDecl->getReferencedProtocols(); for (unsigned i = 0; i < IDecl->getNumIntfRefProtocols(); i++) { if (ProtocolCompatibleWithProtocol(lProto, protoList[i])) return true; + // This is dubious and is added to be compatible with gcc. + // In gcc, it is also allowed assigning a protocol-qualified 'id' + // type to a LHS object when protocol in qualified LHS is in list + // of protocols in the rhs 'id' object. This IMO, should be a bug. + else if (RHSIsQualifiedID && + ProtocolCompatibleWithProtocol(protoList[i], lProto)) + return true; } // 2nd, look up the category. @@ -350,7 +358,8 @@ static bool ClassImplementsProtocol(ObjCProtocolDecl *lProto, // 3rd, look up the super class(s) if (IDecl->getSuperClass()) return - ClassImplementsProtocol(lProto, IDecl->getSuperClass(), lookupCategory); + ClassImplementsProtocol(lProto, IDecl->getSuperClass(), lookupCategory, + RHSIsQualifiedID); return false; } @@ -481,7 +490,7 @@ bool Sema::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs, ObjCInterfaceDecl *lhsID = IT->getDecl(); for (unsigned j = 0; j < rhsQID->getNumProtocols(); j++) { ObjCProtocolDecl *rhsProto = rhsQID->getProtocols(j); - if (!ClassImplementsProtocol(rhsProto, lhsID, compare)) + if (!ClassImplementsProtocol(rhsProto, lhsID, compare, true)) return false; } return true; |