[cfe-commits] r121967 - /cfe/trunk/lib/Sema/SemaTemplate.cpp

Douglas Gregor dgregor at apple.com
Thu Dec 16 07:36:44 PST 2010


Author: dgregor
Date: Thu Dec 16 09:36:43 2010
New Revision: 121967

URL: http://llvm.org/viewvc/llvm-project?rev=121967&view=rev
Log:
Delay the check for unexpanded parameter packs in the types of
non-type template parameters until we know that we have an actual
template declaration of some sort. This cannot be tested yet, but will
become important when we have template template parameter packs.

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

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=121967&r1=121966&r2=121967&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Dec 16 09:36:43 2010
@@ -626,16 +626,10 @@
                                                            PrevDecl);
   }
 
-  if (DiagnoseUnexpandedParameterPack(D.getIdentifierLoc(), TInfo, 
-                                      UPPC_NonTypeTemplateParameterType)) {
+  T = CheckNonTypeTemplateParameterType(T, D.getIdentifierLoc());
+  if (T.isNull()) {
     T = Context.IntTy; // Recover with an 'int' type.
     Invalid = true;
-  } else {  
-    T = CheckNonTypeTemplateParameterType(T, D.getIdentifierLoc());
-    if (T.isNull()) {
-      T = Context.IntTy; // Recover with an 'int' type.
-      Invalid = true;
-    }
   }
   
   NonTypeTemplateParmDecl *Param
@@ -1049,6 +1043,30 @@
   return false;
 }
 
+/// \brief Check for unexpanded parameter packs within the template parameters
+/// of a template template parameter, recursively.
+bool DiagnoseUnexpandedParameterPacks(Sema &S, TemplateTemplateParmDecl *TTP){
+  TemplateParameterList *Params = TTP->getTemplateParameters();
+  for (unsigned I = 0, N = Params->size(); I != N; ++I) {
+    NamedDecl *P = Params->getParam(I);
+    if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) {
+      if (S.DiagnoseUnexpandedParameterPack(NTTP->getLocation(), 
+                                            NTTP->getTypeSourceInfo(),
+                                      Sema::UPPC_NonTypeTemplateParameterType))
+        return true;
+      
+      continue;
+    }
+    
+    if (TemplateTemplateParmDecl *InnerTTP 
+                                        = dyn_cast<TemplateTemplateParmDecl>(P))
+      if (DiagnoseUnexpandedParameterPacks(S, InnerTTP))
+        return true;
+  }
+    
+  return false;
+}
+
 /// \brief Checks the validity of a template parameter list, possibly
 /// considering the template parameter list from a previous
 /// declaration.
@@ -1153,6 +1171,14 @@
         MissingDefaultArg = true;
     } else if (NonTypeTemplateParmDecl *NewNonTypeParm
                = dyn_cast<NonTypeTemplateParmDecl>(*NewParam)) {
+      // Check for unexpanded parameter packs.
+      if (DiagnoseUnexpandedParameterPack(NewNonTypeParm->getLocation(),
+                                          NewNonTypeParm->getTypeSourceInfo(), 
+                                          UPPC_NonTypeTemplateParameterType)) {
+        Invalid = true;
+        continue;
+      }
+
       // Check the presence of a default argument here.
       if (NewNonTypeParm->hasDefaultArgument() && 
           DiagnoseDefaultTemplateArgument(*this, TPC, 
@@ -1191,6 +1217,13 @@
       // Check the presence of a default argument here.
       TemplateTemplateParmDecl *NewTemplateParm
         = cast<TemplateTemplateParmDecl>(*NewParam);
+      
+      // Check for unexpanded parameter packs, recursively.
+      if (DiagnoseUnexpandedParameterPacks(*this, NewTemplateParm)) {
+        Invalid = true;
+        continue;
+      }
+      
       if (NewTemplateParm->hasDefaultArgument() && 
           DiagnoseDefaultTemplateArgument(*this, TPC, 
                                           NewTemplateParm->getLocation(), 





More information about the cfe-commits mailing list