diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-03-11 03:29:50 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-03-11 03:29:50 +0000 |
commit | fc55a8290a3e81111c0a373e1a04b09dd7da0b98 (patch) | |
tree | d1cf9db2ecd57855548311d22eb2a745edce6f17 /lib/Sema/SemaTemplateDeduction.cpp | |
parent | 15dcec73d1e261533c2a32d5f11928570266f7c8 (diff) |
When template argument deduction is ignoring qualifiers, perform deep
structural comparison of non-dependent types. Otherwise, we end up
rejecting cases where the non-dependent types don't match due to
qualifiers in, e.g., a pointee type. Fixes PR12132.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152529 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateDeduction.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateDeduction.cpp | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index f3de38f628..f6ed7d6af9 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -962,14 +962,6 @@ DeduceTemplateArgumentsByTypeMatch(Sema &S, } } - // If the parameter type is not dependent, there is nothing to deduce. - if (!Param->isDependentType()) { - if (!(TDF & TDF_SkipNonDependent) && Param != Arg) - return Sema::TDK_NonDeducedMismatch; - - return Sema::TDK_Success; - } - // C++ [temp.deduct.type]p9: // A template type argument T, a template template argument TT or a // template non-type argument i can be deduced if P and A have one of @@ -1083,6 +1075,17 @@ DeduceTemplateArgumentsByTypeMatch(Sema &S, if (Param.getCVRQualifiers() != Arg.getCVRQualifiers()) return Sema::TDK_NonDeducedMismatch; } + + // If the parameter type is not dependent, there is nothing to deduce. + if (!Param->isDependentType()) { + if (!(TDF & TDF_SkipNonDependent) && Param != Arg) + return Sema::TDK_NonDeducedMismatch; + + return Sema::TDK_Success; + } + } else if (!Param->isDependentType() && + Param.getUnqualifiedType() == Arg.getUnqualifiedType()) { + return Sema::TDK_Success; } switch (Param->getTypeClass()) { @@ -1095,9 +1098,9 @@ DeduceTemplateArgumentsByTypeMatch(Sema &S, case Type::TemplateTypeParm: case Type::SubstTemplateTypeParmPack: llvm_unreachable("Type nodes handled above"); - - // These types cannot be used in templates or cannot be dependent, so - // deduction always fails. + + // These types cannot be dependent, so simply check whether the types are + // the same. case Type::Builtin: case Type::VariableArray: case Type::Vector: @@ -1106,9 +1109,18 @@ DeduceTemplateArgumentsByTypeMatch(Sema &S, case Type::Enum: case Type::ObjCObject: case Type::ObjCInterface: - case Type::ObjCObjectPointer: - return Sema::TDK_NonDeducedMismatch; - + case Type::ObjCObjectPointer: { + if (TDF & TDF_SkipNonDependent) + return Sema::TDK_Success; + + if (TDF & TDF_IgnoreQualifiers) { + Param = Param.getUnqualifiedType(); + Arg = Arg.getUnqualifiedType(); + } + + return Param == Arg? Sema::TDK_Success : Sema::TDK_NonDeducedMismatch; + } + // _Complex T [placeholder extension] case Type::Complex: if (const ComplexType *ComplexArg = Arg->getAs<ComplexType>()) @@ -1411,7 +1423,8 @@ DeduceTemplateArgumentsByTypeMatch(Sema &S, return DeduceTemplateArgumentsByTypeMatch(S, TemplateParams, QualType(MemPtrParam->getClass(), 0), QualType(MemPtrArg->getClass(), 0), - Info, Deduced, 0); + Info, Deduced, + TDF & TDF_IgnoreQualifiers); } // (clang extension) |