From: John McCall Date: Sat, 28 Aug 2010 22:14:41 +0000 (+0000) Subject: When perform exact-qualifier-match template argument deduction, X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cd05e81e2e2640a0a0097658c660afc6c8a9f4fd;p=clang When perform exact-qualifier-match template argument deduction, properly account for the possibility that certain opaque types might be more qualified than they appear. Fixes PR7708. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112390 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index 4691181111..87d9febfb1 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -350,6 +350,29 @@ DeduceTemplateArguments(Sema &S, return Sema::TDK_Success; } +/// \brief Determines whether the given type is an opaque type that +/// might be more qualified when instantiated. +static bool IsPossiblyOpaquelyQualifiedType(QualType T) { + switch (T->getTypeClass()) { + case Type::TypeOfExpr: + case Type::TypeOf: + case Type::DependentName: + case Type::Decltype: + case Type::UnresolvedUsing: + return true; + + case Type::ConstantArray: + case Type::IncompleteArray: + case Type::VariableArray: + case Type::DependentSizedArray: + return IsPossiblyOpaquelyQualifiedType( + cast(T)->getElementType()); + + default: + return false; + } +} + /// \brief Deduce the template arguments by comparing the parameter type and /// the argument type (C++ [temp.deduct.type]). /// @@ -474,7 +497,7 @@ DeduceTemplateArguments(Sema &S, if (TDF & TDF_ParamWithReferenceType) { if (Param.isMoreQualifiedThan(Arg)) return Sema::TDK_NonDeducedMismatch; - } else { + } else if (!IsPossiblyOpaquelyQualifiedType(Param)) { if (Param.getCVRQualifiers() != Arg.getCVRQualifiers()) return Sema::TDK_NonDeducedMismatch; } diff --git a/test/SemaTemplate/deduction.cpp b/test/SemaTemplate/deduction.cpp index c4c668898f..9400a0aba9 100644 --- a/test/SemaTemplate/deduction.cpp +++ b/test/SemaTemplate/deduction.cpp @@ -121,3 +121,16 @@ namespace test1 { foo(a); } } + +// PR7708 +namespace test2 { + template struct Const { typedef void const type; }; + + template void f(T, typename Const::type*); + template void f(T, void const *); + + void test() { + void *p = 0; + f(0, p); + } +}