[cfe-commits] r122532 - in /cfe/trunk: lib/AST/DeclPrinter.cpp lib/AST/StmtProfile.cpp lib/Sema/SemaTemplateInstantiate.cpp lib/Sema/SemaTemplateVariadic.cpp test/CXX/temp/temp.decls/temp.variadic/p4.cpp

Douglas Gregor dgregor at apple.com
Thu Dec 23 16:15:10 PST 2010


Author: dgregor
Date: Thu Dec 23 18:15:10 2010
New Revision: 122532

URL: http://llvm.org/viewvc/llvm-project?rev=122532&view=rev
Log:
When instantiating a non-type template parameter pack, be sure to
extract the appropriate argument from the argument pack (based on the
current substitution index, of course). Simple instantiation of pack
expansions involving non-type template parameter packs now works.

Modified:
    cfe/trunk/lib/AST/DeclPrinter.cpp
    cfe/trunk/lib/AST/StmtProfile.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
    cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
    cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p4.cpp

Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=122532&r1=122531&r2=122532&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Thu Dec 23 18:15:10 2010
@@ -681,6 +681,9 @@
                  dyn_cast<NonTypeTemplateParmDecl>(Param)) {
       Out << NTTP->getType().getAsString(Policy);
 
+      if (NTTP->isParameterPack() && !isa<PackExpansionType>(NTTP->getType()))
+        Out << "...";
+        
       if (IdentifierInfo *Name = NTTP->getIdentifier()) {
         Out << ' ';
         Out << Name->getName();

Modified: cfe/trunk/lib/AST/StmtProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=122532&r1=122531&r2=122532&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtProfile.cpp (original)
+++ cfe/trunk/lib/AST/StmtProfile.cpp Thu Dec 23 18:15:10 2010
@@ -894,6 +894,7 @@
     if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
       ID.AddInteger(NTTP->getDepth());
       ID.AddInteger(NTTP->getIndex());
+      ID.AddInteger(NTTP->isParameterPack());
       VisitType(NTTP->getType());
       return;
     }

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=122532&r1=122531&r2=122532&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Thu Dec 23 18:15:10 2010
@@ -638,7 +638,7 @@
     ExprResult TransformDeclRefExpr(DeclRefExpr *E);
     ExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E);
     ExprResult TransformTemplateParmRefExpr(DeclRefExpr *E,
-                                                NonTypeTemplateParmDecl *D);
+                                            NonTypeTemplateParmDecl *D);
 
     QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
                                         FunctionProtoTypeLoc TL);
@@ -836,8 +836,19 @@
                                         NTTP->getPosition()))
     return SemaRef.Owned(E);
 
-  const TemplateArgument &Arg = TemplateArgs(NTTP->getDepth(),
-                                             NTTP->getPosition());
+  TemplateArgument Arg = TemplateArgs(NTTP->getDepth(), NTTP->getPosition());
+  if (NTTP->isParameterPack()) {
+    assert(Arg.getKind() == TemplateArgument::Pack && 
+           "Missing argument pack");
+    
+    if (getSema().ArgumentPackSubstitutionIndex == -1) {
+      // FIXME: Variadic templates fun case.
+      getSema().Diag(Loc, diag::err_pack_expansion_mismatch_unsupported);
+      return ExprError();
+    }
+    
+    Arg = Arg.pack_begin()[getSema().ArgumentPackSubstitutionIndex];
+  }
 
   // The template argument itself might be an expression, in which
   // case we just return that expression.
@@ -876,7 +887,6 @@
 TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) {
   NamedDecl *D = E->getDecl();
   if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
-    // FIXME: Variadic templates index substitution.
     if (NTTP->getDepth() < TemplateArgs.getNumLevels())
       return TransformTemplateParmRefExpr(E, NTTP);
     

Modified: cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp?rev=122532&r1=122531&r2=122532&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp Thu Dec 23 18:15:10 2010
@@ -395,7 +395,7 @@
     
     // If we don't have a template argument at this depth/index, then we 
     // cannot expand the pack expansion. Make a note of this, but we still 
-    // want to check that any parameter packs we *do* have arguments for.
+    // want to check any parameter packs we *do* have arguments for.
     if (!TemplateArgs.hasTemplateArgument(Depth, Index)) {
       ShouldExpand = false;
       continue;

Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p4.cpp?rev=122532&r1=122531&r2=122532&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p4.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p4.cpp Thu Dec 23 18:15:10 2010
@@ -1,6 +1,22 @@
 // RUN: %clang_cc1 -std=c++0x -fsyntax-only -fexceptions -verify %s
 
 template<typename... Types> struct tuple;
+template<int I> struct int_c;
+
+template<typename T>
+struct identity {
+  typedef T type;
+};
+
+template<typename T, typename U>
+struct is_same {
+  static const bool value = false;
+};
+
+template<typename T>
+struct is_same<T, T> {
+  static const bool value = true;
+};
 
 // FIXME: Many more bullets to go
 
@@ -18,15 +34,19 @@
   typedef tuple<typename Types::type...> types;
 };
 
-template<typename T>
-struct identity {
-  typedef T type;
-};
-
 tuple<int, float> *t_int_float;
 extract_nested_types<identity<int>, identity<float> >::types *t_int_float_2 
   = t_int_float;
 
+template<int ...N>
+struct tuple_of_ints {
+  typedef tuple<int_c<N>...> type;
+};
+
+int check_temp_arg_1[is_same<tuple_of_ints<1, 2, 3, 4, 5>::type, 
+                             tuple<int_c<1>, int_c<2>, int_c<3>, int_c<4>, 
+                                   int_c<5>>>::value? 1 : -1];
+
 // In a dynamic-exception-specification (15.4); the pattern is a type-id.
 template<typename ...Types>
 struct f_with_except {





More information about the cfe-commits mailing list