diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 0d1dc4e4d176..0528a58f8944 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -3540,14 +3540,14 @@ bool ASTContext::QIdProtocolsAdoptObjCObjectProtocols(QualType QT, return false; if (!IDecl->hasDefinition()) return false; - ObjCInterfaceDecl::protocol_iterator PI = IDecl->protocol_begin(), - E = IDecl->protocol_end(); - if (PI == E) - return (IDecl->getSuperClass() - ? QIdProtocolsAdoptObjCObjectProtocols(QT, IDecl->getSuperClass()) - : false); - - for (; PI != E; ++PI) { + llvm::SmallPtrSet InheritedProtocols; + CollectInheritedProtocols(IDecl, InheritedProtocols); + if (InheritedProtocols.empty()) + return false; + + for (llvm::SmallPtrSet::iterator PI = + InheritedProtocols.begin(), + E = InheritedProtocols.end(); PI != E; ++PI) { // If both the right and left sides have qualifiers. bool Adopts = false; for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(), @@ -3558,9 +3558,7 @@ bool ASTContext::QIdProtocolsAdoptObjCObjectProtocols(QualType QT, break; } if (!Adopts) - return (IDecl->getSuperClass() - ? QIdProtocolsAdoptObjCObjectProtocols(QT, IDecl->getSuperClass()) - : false); + return false; } return true; } diff --git a/clang/test/SemaObjC/objcbridge-attribute.m b/clang/test/SemaObjC/objcbridge-attribute.m index c5bf9f843d51..24b7289f8d9a 100644 --- a/clang/test/SemaObjC/objcbridge-attribute.m +++ b/clang/test/SemaObjC/objcbridge-attribute.m @@ -51,6 +51,7 @@ typedef CFErrorRef1 CFErrorRef2; // expected-note {{declared here}} @protocol P2 @end @protocol P3 @end @protocol P4 @end +@protocol P5 @end @interface NSError @end // expected-note 5 {{declared here}} @@ -103,3 +104,26 @@ void Test6(id P123, id ID, id P1234, id P12, (void)(CFMyErrorRef)P12; // expected-warning {{'id' cannot bridge to 'CFMyErrorRef' (aka 'struct __CFMyErrorRef *')}} (void)(CFMyErrorRef)P23; // expected-warning {{'id' cannot bridge to 'CFMyErrorRef' (aka 'struct __CFMyErrorRef *')}} } + +typedef struct __attribute__ ((objc_bridge(MyPersonalError))) __CFMyPersonalErrorRef * CFMyPersonalErrorRef; // expected-note 4 {{declared here}} + +@interface MyPersonalError : NSError // expected-note 4 {{declared here}} +@end + +void Test7(id P123, id ID, id P1234, id P12, id P23) { + (void)(CFMyPersonalErrorRef)ID; // ok + (void)(CFMyPersonalErrorRef)P123; // expected-warning {{'id' cannot bridge to 'CFMyPersonalErrorRef' (aka 'struct __CFMyPersonalErrorRef *')}} + (void)(CFMyPersonalErrorRef)P1234; // ok + (void)(CFMyPersonalErrorRef)P12; // expected-warning {{'id' cannot bridge to 'CFMyPersonalErrorRef' (aka 'struct __CFMyPersonalErrorRef *')}} + (void)(CFMyPersonalErrorRef)P23; // expected-warning {{'id' cannot bridge to 'CFMyPersonalErrorRef' (aka 'struct __CFMyPersonalErrorRef *')}} +} + +void Test8(CFMyPersonalErrorRef cf) { + (void)(id)cf; // ok + (void)(id)cf; // ok + (void)(id)cf; // ok + (void)(id)cf; // ok + (void)(id)cf; // ok + (void)(id)cf; // expected-warning {{'CFMyPersonalErrorRef' (aka 'struct __CFMyPersonalErrorRef *') bridges to MyPersonalError, not 'id'}} +} +