From 4a5c15f75f76b95e1c2ceb6fa2737dcadd5f4be1 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 30 Sep 2009 22:13:51 +0000 Subject: [PATCH] Improve template argument deduction in the case where the parameter type is a template-id (e.g., basic_ostream) and the argument type is a class that has a derived class matching the parameter type. Previously, we were giving up on template argument deduction too early. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83177 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplateDeduction.cpp | 8 +------- .../temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp | 4 +++- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index 64b7f8b140..b981389d1d 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -651,8 +651,7 @@ DeduceTemplateArguments(ASTContext &Context, = DeduceTemplateArguments(Context, TemplateParams, SpecParam, Arg, Info, Deduced); - if (Result && (TDF & TDF_DerivedClass) && - Result != Sema::TDK_Inconsistent) { + if (Result && (TDF & TDF_DerivedClass)) { // C++ [temp.deduct.call]p3b3: // If P is a class, and P has the form template-id, then A can be a // derived class of the deduced A. Likewise, if P is a pointer to a @@ -690,11 +689,6 @@ DeduceTemplateArguments(ASTContext &Context, // note that we had some success. if (BaseResult == Sema::TDK_Success) Successful = true; - // If deduction against this base resulted in an inconsistent - // set of deduced template arguments, template argument - // deduction fails. - else if (BaseResult == Sema::TDK_Inconsistent) - return BaseResult; } // Visit base classes diff --git a/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp b/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp index 596427adf9..dbe2ff3e18 100644 --- a/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp +++ b/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp @@ -66,6 +66,7 @@ template struct C { }; struct D : public C { }; struct E : public D { }; struct F : A { }; +struct G : A, C { }; template C *f4a(const C&); @@ -75,12 +76,13 @@ template C *f4c(C*); int *f4c(...); -void test_f4(D d, E e, F f) { +void test_f4(D d, E e, F f, G g) { C *ci1a = f4a(d); C *ci2a = f4a(e); C *ci1b = f4b(d); C *ci2b = f4b(e); C *ci1c = f4c(&d); C *ci2c = f4c(&e); + C *ci3c = f4c(&g); int *ip1 = f4c(&f); } -- 2.40.0