[cfe-commits] r126819 - in /cfe/trunk: include/clang/AST/RecursiveASTVisitor.h lib/Sema/SemaTemplateInstantiate.cpp lib/Sema/TreeTransform.h test/CXX/temp/temp.decls/temp.variadic/multi-level-substitution.cpp

Douglas Gregor dgregor at apple.com
Tue Mar 1 18:04:06 PST 2011


Author: dgregor
Date: Tue Mar  1 20:04:06 2011
New Revision: 126819

URL: http://llvm.org/viewvc/llvm-project?rev=126819&view=rev
Log:
When we're substituting into a parameter-type-list nested inside the pattern
of an expansion, and we have a paramameter that is not a parameter
pack, don't suppress substitution of parameter packs within this
context.


Modified:
    cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
    cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
    cfe/trunk/lib/Sema/TreeTransform.h
    cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/multi-level-substitution.cpp

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=126819&r1=126818&r2=126819&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Tue Mar  1 20:04:06 2011
@@ -600,8 +600,8 @@
     // FIXME: how can TSI ever be NULL?
     if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo())
       return getDerived().TraverseTypeLoc(TSI->getTypeLoc());
-    else
-      return true;
+    else 
+      getDerived().TraverseType(Arg.getAsType());
   }
 
   case TemplateArgument::Template:
@@ -933,7 +933,11 @@
     const FunctionProtoType *T = TL.getTypePtr();
 
     for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
-      TRY_TO(TraverseDecl(TL.getArg(I)));
+      if (TL.getArg(I)) {
+        TRY_TO(TraverseDecl(TL.getArg(I)));
+      } else if (I < T->getNumArgs()) {
+        TRY_TO(TraverseType(T->getArgType(I)));
+      }
     }
 
     for (FunctionProtoType::exception_iterator E = T->exception_begin(),
@@ -1468,6 +1472,8 @@
   TRY_TO(TraverseNestedNameSpecifier(D->getQualifier()));
   if (D->getTypeSourceInfo())
     TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
+  else
+    TRY_TO(TraverseType(D->getType()));
   return true;
 }
 

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=126819&r1=126818&r2=126819&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Tue Mar  1 20:04:06 2011
@@ -1510,6 +1510,7 @@
     }
 
     SourceLocation EllipsisLoc;
+    TypeSourceInfo *BaseTypeLoc;
     if (Base->isPackExpansion()) {
       // This is a pack expansion. See whether we should expand it now, or
       // wait until later.
@@ -1560,13 +1561,18 @@
       
       // The resulting base specifier will (still) be a pack expansion.
       EllipsisLoc = Base->getEllipsisLoc();
+      Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, -1);
+      BaseTypeLoc = SubstType(Base->getTypeSourceInfo(),
+                              TemplateArgs,
+                              Base->getSourceRange().getBegin(),
+                              DeclarationName());
+    } else {
+      BaseTypeLoc = SubstType(Base->getTypeSourceInfo(),
+                              TemplateArgs,
+                              Base->getSourceRange().getBegin(),
+                              DeclarationName());
     }
     
-    Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, -1);
-    TypeSourceInfo *BaseTypeLoc = SubstType(Base->getTypeSourceInfo(),
-                                            TemplateArgs,
-                                            Base->getSourceRange().getBegin(),
-                                            DeclarationName());
     if (!BaseTypeLoc) {
       Invalid = true;
       continue;

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=126819&r1=126818&r2=126819&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Tue Mar  1 20:04:06 2011
@@ -3827,6 +3827,7 @@
   for (unsigned i = 0; i != NumParams; ++i) {
     if (ParmVarDecl *OldParm = Params[i]) {
       llvm::Optional<unsigned> NumExpansions;
+      ParmVarDecl *NewParm = 0;
       if (OldParm->isParameterPack()) {
         // We have a function parameter pack that may need to be expanded.
         llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
@@ -3836,7 +3837,8 @@
         PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
         TypeLoc Pattern = ExpansionTL.getPatternLoc();
         SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
-        
+        assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
+
         // Determine whether we should expand the parameter packs.
         bool ShouldExpand = false;
         bool RetainExpansion = false;
@@ -3891,11 +3893,14 @@
         
         // We'll substitute the parameter now without expanding the pack 
         // expansion.
+        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
+        NewParm = getDerived().TransformFunctionTypeParam(OldParm,
+                                                          NumExpansions);
+      } else {
+        NewParm = getDerived().TransformFunctionTypeParam(OldParm,
+                                                  llvm::Optional<unsigned>());
       }
-      
-      Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
-      ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
-                                                                 NumExpansions);
+
       if (!NewParm)
         return true;
       
@@ -3910,6 +3915,7 @@
     QualType OldType = ParamTypes[i];
     bool IsPackExpansion = false;
     llvm::Optional<unsigned> NumExpansions;
+    QualType NewType;
     if (const PackExpansionType *Expansion 
                                        = dyn_cast<PackExpansionType>(OldType)) {
       // We have a function parameter pack that may need to be expanded.
@@ -3964,10 +3970,12 @@
       // expansion.
       OldType = Expansion->getPattern();
       IsPackExpansion = true;
+      Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
+      NewType = getDerived().TransformType(OldType);
+    } else {
+      NewType = getDerived().TransformType(OldType);
     }
     
-    Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
-    QualType NewType = getDerived().TransformType(OldType);
     if (NewType.isNull())
       return true;
 

Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/multi-level-substitution.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/multi-level-substitution.cpp?rev=126819&r1=126818&r2=126819&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/multi-level-substitution.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/multi-level-substitution.cpp Tue Mar  1 20:04:06 2011
@@ -216,3 +216,21 @@
 
   tuple_of_values<int&, float&>::apply<i, f, i>::type tv4; // expected-error{{too many template arguments for class template 'apply'}}
 }
+
+namespace ExpandingFunctionParameters {
+  template<typename ...T>
+  struct X0 {
+    typedef int type;
+  };
+
+  template<typename ...T>
+  struct X1 {
+    template<typename ... U>
+    typename X0<T(T, U...)...>::type f(U...);
+  };
+
+  void test() {
+    X1<float> x1;
+    x1.f(17, 3.14159);
+  }
+}





More information about the cfe-commits mailing list