When performing template argument deduction, match Objective C pointers

against pointer patterns.

llvm-svn: 103706
This commit is contained in:
John McCall 2010-05-13 07:48:05 +00:00
parent 7100860ef5
commit bb4ea81ab9
2 changed files with 33 additions and 3 deletions

View File

@ -482,14 +482,20 @@ DeduceTemplateArguments(Sema &S,
// T *
case Type::Pointer: {
const PointerType *PointerArg = Arg->getAs<PointerType>();
if (!PointerArg)
QualType PointeeType;
if (const PointerType *PointerArg = Arg->getAs<PointerType>()) {
PointeeType = PointerArg->getPointeeType();
} else if (const ObjCObjectPointerType *PointerArg
= Arg->getAs<ObjCObjectPointerType>()) {
PointeeType = PointerArg->getPointeeType();
} else {
return Sema::TDK_NonDeducedMismatch;
}
unsigned SubTDF = TDF & (TDF_IgnoreQualifiers | TDF_DerivedClass);
return DeduceTemplateArguments(S, TemplateParams,
cast<PointerType>(Param)->getPointeeType(),
PointerArg->getPointeeType(),
PointeeType,
Info, Deduced, SubTDF);
}

View File

@ -0,0 +1,24 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
@class NSString;
// Reduced from WebKit.
namespace test0 {
template <typename T> struct RemovePointer {
typedef T Type;
};
template <typename T> struct RemovePointer<T*> {
typedef T Type;
};
template <typename T> struct RetainPtr {
typedef typename RemovePointer<T>::Type ValueType;
typedef ValueType* PtrType;
RetainPtr(PtrType ptr);
};
void test(NSString *S) {
RetainPtr<NSString*> ptr(S);
}
}