From: Anders Carlsson Date: Tue, 16 Jun 2009 23:08:29 +0000 (+0000) Subject: Since integral template arguments can't have dependent types we don't need an extra... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=25af1ed6ffa46a333886264299be98a838097b34;p=clang Since integral template arguments can't have dependent types we don't need an extra pass to set the right APSInt bit width/signedness. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73580 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index 33a7c66842..c9b6e13d4a 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -53,9 +53,15 @@ DeduceNonTypeTemplateArgument(ASTContext &Context, "Cannot deduce non-type template argument with depth > 0"); if (Deduced[NTTP->getIndex()].isNull()) { - Deduced[NTTP->getIndex()] = TemplateArgument(SourceLocation(), - llvm::APSInt(Value), - NTTP->getType()); + QualType T = NTTP->getType(); + + // FIXME: Make sure we didn't overflow our data type! + unsigned AllowedBits = Context.getTypeSize(T); + if (Value.getBitWidth() != AllowedBits) + Value.extOrTrunc(AllowedBits); + Value.setIsSigned(T->isSignedIntegerType()); + + Deduced[NTTP->getIndex()] = TemplateArgument(SourceLocation(), Value, T); return Sema::TDK_Success; } @@ -672,35 +678,6 @@ Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, /*FlattenArgs=*/true); Info.reset(DeducedArgumentList); - // Now that we have all of the deduced template arguments, take - // another pass through them to convert any integral template - // arguments to the appropriate type. - for (unsigned I = 0, N = Deduced.size(); I != N; ++I) { - TemplateArgument &Arg = Deduced[I]; - if (Arg.getKind() == TemplateArgument::Integral) { - const NonTypeTemplateParmDecl *Parm - = cast(Partial->getTemplateParameters() - ->getParam(I)); - QualType T = InstantiateType(Parm->getType(), *DeducedArgumentList, - Parm->getLocation(), Parm->getDeclName()); - if (T.isNull()) { - Info.Param = const_cast(Parm); - Info.FirstArg = TemplateArgument(Parm->getLocation(), Parm->getType()); - return TDK_SubstitutionFailure; - } - - // FIXME: Make sure we didn't overflow our data type! - llvm::APSInt &Value = *Arg.getAsIntegral(); - unsigned AllowedBits = Context.getTypeSize(T); - if (Value.getBitWidth() != AllowedBits) - Value.extOrTrunc(AllowedBits); - Value.setIsSigned(T->isSignedIntegerType()); - Arg.setIntegralType(T); - } - - (*DeducedArgumentList)[I] = Arg; - } - // Substitute the deduced template arguments into the template // arguments of the class template partial specialization, and // verify that the instantiated template arguments are both valid