From 38175a2e751593c24eb63679191572ed250c6d4c Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 28 Sep 2016 22:08:38 +0000 Subject: Fix bug where template argument deduction of a non-type template parameter used as a template argument in a template-id, from a null non-type template argument, failed. Extracted from a patch by James Touton! llvm-svn: 282641 --- clang/lib/Sema/SemaTemplateDeduction.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'clang/lib') diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index f8e825ff941..2311b2b7447 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -285,7 +285,7 @@ checkDeducedTemplateArguments(ASTContext &Context, } /// \brief Deduce the value of the given non-type template parameter -/// from the given constant. +/// from the given integral constant. static Sema::TemplateDeductionResult DeduceNonTypeTemplateArgument( Sema &S, NonTypeTemplateParmDecl *NTTP, const llvm::APSInt &Value, QualType ValueType, bool DeducedFromArrayBound, TemplateDeductionInfo &Info, @@ -309,6 +309,32 @@ static Sema::TemplateDeductionResult DeduceNonTypeTemplateArgument( return Sema::TDK_Success; } +/// \brief Deduce the value of the given non-type template parameter +/// from the given null pointer template argument type. +static Sema::TemplateDeductionResult DeduceNullPtrTemplateArgument( + Sema &S, NonTypeTemplateParmDecl *NTTP, QualType NullPtrType, + TemplateDeductionInfo &Info, + SmallVectorImpl &Deduced) { + Expr *Value = + S.ImpCastExprToType(new (S.Context) CXXNullPtrLiteralExpr( + S.Context.NullPtrTy, NTTP->getLocation()), + NullPtrType, CK_NullToPointer) + .get(); + DeducedTemplateArgument NewDeduced(Value); + DeducedTemplateArgument Result = checkDeducedTemplateArguments( + S.Context, Deduced[NTTP->getIndex()], NewDeduced); + + if (Result.isNull()) { + Info.Param = NTTP; + Info.FirstArg = Deduced[NTTP->getIndex()]; + Info.SecondArg = NewDeduced; + return Sema::TDK_Inconsistent; + } + + Deduced[NTTP->getIndex()] = Result; + return Sema::TDK_Success; +} + /// \brief Deduce the value of the given non-type template parameter /// from the given type- or value-dependent expression. /// @@ -1758,6 +1784,9 @@ DeduceTemplateArguments(Sema &S, Arg.getIntegralType(), /*ArrayBound=*/false, Info, Deduced); + if (Arg.getKind() == TemplateArgument::NullPtr) + return DeduceNullPtrTemplateArgument(S, NTTP, Arg.getNullPtrType(), + Info, Deduced); if (Arg.getKind() == TemplateArgument::Expression) return DeduceNonTypeTemplateArgument(S, NTTP, Arg.getAsExpr(), Info, Deduced); -- cgit v1.2.3