]> granicus.if.org Git - clang/commitdiff
For the sake of Objective-c++ overload resolution,
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 3 May 2010 21:06:18 +0000 (21:06 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 3 May 2010 21:06:18 +0000 (21:06 +0000)
treat argument types of objective-c pointer types
which only differ in their protocol qualifiers as
the same type (radar 7925668).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102955 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaOverload.cpp

index ba20ed1e1a7f5b835cf5f78dde095db66fe4e68c..e6cf0599b4268406f76c220788493f52c70b3171 100644 (file)
@@ -1109,6 +1109,9 @@ public:
                            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,
index 2a2521a32c208a301d20d248006fdbab5daf9625..21f2a51040ecaa0d2240b2e7a12c3ffb66531a94 100644 (file)
@@ -374,8 +374,7 @@ bool Sema::IsOverload(FunctionDecl *New, FunctionDecl *Old) {
   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 @@ bool Sema::isObjCPointerConversion(QualType FromType, QualType ToType,
 
   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