diff options
author | Anders Carlsson <andersca@mac.com> | 2009-06-16 23:08:29 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-06-16 23:08:29 +0000 |
commit | 25af1ed6ffa46a333886264299be98a838097b34 (patch) | |
tree | 28486cb0f535074097c68249fbda5665788bee5e /lib/Sema/SemaTemplateDeduction.cpp | |
parent | cb7835f4f9b681c548f256b62b0810289d4856cd (diff) |
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
Diffstat (limited to 'lib/Sema/SemaTemplateDeduction.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateDeduction.cpp | 41 |
1 files changed, 9 insertions, 32 deletions
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<NonTypeTemplateParmDecl>(Partial->getTemplateParameters() - ->getParam(I)); - QualType T = InstantiateType(Parm->getType(), *DeducedArgumentList, - Parm->getLocation(), Parm->getDeclName()); - if (T.isNull()) { - Info.Param = const_cast<NonTypeTemplateParmDecl*>(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 |