From ee9ca6966d63419e4da1ea54151864a4ed8daeed Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 15 Mar 2010 18:36:00 +0000 Subject: [PATCH] objective-c++ must take into account qualifiers when considering valid objc pointer converions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98557 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaOverload.cpp | 6 ++++++ test/SemaObjCXX/objc-pointer-conv.mm | 12 ++++++++++++ 2 files changed, 18 insertions(+) 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'}} +} +