[cfe-commits] r102955 - in /cfe/trunk/lib/Sema: Sema.h SemaOverload.cpp
Fariborz Jahanian
fjahanian at apple.com
Mon May 3 14:06:18 PDT 2010
Author: fjahanian
Date: Mon May 3 16:06:18 2010
New Revision: 102955
URL: http://llvm.org/viewvc/llvm-project?rev=102955&view=rev
Log:
For the sake of Objective-c++ overload resolution,
treat argument types of objective-c pointer types
which only differ in their protocol qualifiers as
the same type (radar 7925668).
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaOverload.cpp
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=102955&r1=102954&r2=102955&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Mon May 3 16:06:18 2010
@@ -1109,6 +1109,9 @@
QualType& ConvertedType, bool &IncompatibleObjC);
bool isObjCPointerConversion(QualType FromType, QualType ToType,
QualType& ConvertedType, bool &IncompatibleObjC);
+ bool FunctionArgTypesAreEqual (FunctionProtoType* OldType,
+ FunctionProtoType* NewType);
+
bool CheckPointerConversion(Expr *From, QualType ToType,
CastExpr::CastKind &Kind,
CXXBaseSpecifierArray& BasePath,
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=102955&r1=102954&r2=102955&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Mon May 3 16:06:18 2010
@@ -374,8 +374,7 @@
if (OldQType != NewQType &&
(OldType->getNumArgs() != NewType->getNumArgs() ||
OldType->isVariadic() != NewType->isVariadic() ||
- !std::equal(OldType->arg_type_begin(), OldType->arg_type_end(),
- NewType->arg_type_begin())))
+ !FunctionArgTypesAreEqual(OldType, NewType)))
return true;
// C++ [temp.over.link]p4:
@@ -1332,6 +1331,47 @@
return false;
}
+
+/// FunctionArgTypesAreEqual - This routine checks two function proto types
+/// for equlity of their argument types. Caller has already checked that
+/// they have same number of arguments. This routine assumes that Objective-C
+/// pointer types which only differ in their protocol qualifiers are equal.
+bool Sema::FunctionArgTypesAreEqual(FunctionProtoType* OldType,
+ FunctionProtoType* NewType){
+ if (!getLangOptions().ObjC1)
+ return std::equal(OldType->arg_type_begin(), OldType->arg_type_end(),
+ NewType->arg_type_begin());
+
+ for (FunctionProtoType::arg_type_iterator O = OldType->arg_type_begin(),
+ N = NewType->arg_type_begin(),
+ E = OldType->arg_type_end(); O && (O != E); ++O, ++N) {
+ QualType ToType = (*O);
+ QualType FromType = (*N);
+ if (ToType != FromType) {
+ if (const PointerType *PTTo = ToType->getAs<PointerType>()) {
+ if (const PointerType *PTFr = FromType->getAs<PointerType>())
+ if (PTTo->getPointeeType()->isObjCQualifiedIdType() &&
+ PTFr->getPointeeType()->isObjCQualifiedIdType() ||
+ PTTo->getPointeeType()->isObjCQualifiedClassType() &&
+ PTFr->getPointeeType()->isObjCQualifiedClassType())
+ continue;
+ }
+ else if (ToType->isObjCObjectPointerType() &&
+ FromType->isObjCObjectPointerType()) {
+ QualType ToInterfaceTy = ToType->getPointeeType();
+ QualType FromInterfaceTy = FromType->getPointeeType();
+ if (const ObjCInterfaceType *OITTo =
+ ToInterfaceTy->getAs<ObjCInterfaceType>())
+ if (const ObjCInterfaceType *OITFr =
+ FromInterfaceTy->getAs<ObjCInterfaceType>())
+ if (OITTo->getDecl() == OITFr->getDecl())
+ continue;
+ }
+ return false;
+ }
+ }
+ return true;
+}
/// CheckPointerConversion - Check the pointer conversion from the
/// expression From to the type ToType. This routine checks for
More information about the cfe-commits
mailing list