diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index ff59fc3a7d..a58b33f97f 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -1135,6 +1135,12 @@ bool Sema::isObjCPointerConversion(QualType FromType, QualType ToType, // Objective C++: We're able to convert from a pointer to an // interface to a pointer to a different interface. if (Context.canAssignObjCInterfaces(ToObjCPtr, FromObjCPtr)) { + const ObjCInterfaceType* LHS = ToObjCPtr->getInterfaceType(); + const ObjCInterfaceType* RHS = FromObjCPtr->getInterfaceType(); + if (getLangOptions().CPlusPlus && LHS && RHS && + !ToObjCPtr->getPointeeType().isAtLeastAsQualifiedAs( + FromObjCPtr->getPointeeType())) + return false; ConvertedType = ToType; return true; } diff --git a/test/SemaObjCXX/objc-pointer-conv.mm b/test/SemaObjCXX/objc-pointer-conv.mm index c03e3aaad3..144bda4390 100644 --- a/test/SemaObjCXX/objc-pointer-conv.mm +++ b/test/SemaObjCXX/objc-pointer-conv.mm @@ -24,3 +24,15 @@ void RandomFunc(CFMDRef theDict, const void *key, const void *value); RandomFunc((CFMDRef)dict, key, objects[3]); } @end + +@interface I +- (void) Meth : (I*) Arg; +@end + +void Func (I* arg); // expected-note {{candidate function not viable: no known conversion from 'I const *' to 'I *' for 1st argument}} + +void foo(const I *p, I* sel) { + [sel Meth : p]; // expected-error {{incompatible type sending 'I const *', expected 'I *'}} + Func(p); // expected-error {{no matching function for call to 'Func'}} +} +