[cfe-commits] r73580 - /cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp

Anders Carlsson andersca at mac.com
Tue Jun 16 16:08:29 PDT 2009


Author: andersca
Date: Tue Jun 16 18:08:29 2009
New Revision: 73580

URL: http://llvm.org/viewvc/llvm-project?rev=73580&view=rev
Log:
Since integral template arguments can't have dependent types we don't need an extra pass to set the right APSInt bit width/signedness.

Modified:
    cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=73580&r1=73579&r2=73580&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Tue Jun 16 18:08:29 2009
@@ -53,9 +53,15 @@
          "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 @@
                                          /*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





More information about the cfe-commits mailing list