]> granicus.if.org Git - clang/commitdiff
Diagnose the presence of unexpanded parameter packs within class
authorDouglas Gregor <dgregor@apple.com>
Mon, 3 Jan 2011 20:35:03 +0000 (20:35 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 3 Jan 2011 20:35:03 +0000 (20:35 +0000)
template partial specialization arguments.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122769 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Sema/Sema.h
lib/Sema/SemaTemplate.cpp
lib/Sema/SemaTemplateVariadic.cpp
test/CXX/temp/temp.decls/temp.variadic/p5.cpp

index eb123b9fe9f32a7ba45946c73d558f87a6628e21..c8d2678e88dc317851e05692100b57009587fff7 100644 (file)
@@ -1836,25 +1836,25 @@ def err_unexpanded_parameter_pack_0 : Error<
   "%select{expression|base type|declaration type|data member type|bit-field "
   "size|static assertion|fixed underlying type|enumerator value|"
   "using declaration|friend declaration|qualifier|initializer|default argument|"
-  "non-type template parameter type|exception type}0 "
+  "non-type template parameter type|exception type|partial specialization}0 "
   "contains an unexpanded parameter pack">;
 def err_unexpanded_parameter_pack_1 : Error<
   "%select{expression|base type|declaration type|data member type|bit-field "
   "size|static assertion|fixed underlying type|enumerator value|"
   "using declaration|friend declaration|qualifier|initializer|default argument|"
-  "non-type template parameter type|exception type}0 "
+  "non-type template parameter type|exception type|partial specialization}0 "
   "contains unexpanded parameter pack %1">;
 def err_unexpanded_parameter_pack_2 : Error<
   "%select{expression|base type|declaration type|data member type|bit-field "
   "size|static assertion|fixed underlying type|enumerator value|"
   "using declaration|friend declaration|qualifier|initializer|default argument|"
-  "non-type template parameter type|exception type}0 "
+  "non-type template parameter type|exception type|partial specialization}0 "
   "contains unexpanded parameter packs %1 and %2">;
 def err_unexpanded_parameter_pack_3_or_more : Error<
   "%select{expression|base type|declaration type|data member type|bit-field "
   "size|static assertion|fixed underlying type|enumerator value|"
   "using declaration|friend declaration|qualifier|initializer|default argument|"
-  "non-type template parameter type|exception type}0 "
+  "non-type template parameter type|exception type|partial specialization}0 "
   "contains unexpanded parameter packs %1, %2, ...">;
 
 def err_pack_expansion_without_parameter_packs : Error<
index 05bb1258c1b3fb2567035ff179b119acf9ea8d98..2d349bc34c2fd9312e3d2083755f2ac35a2b27f3 100644 (file)
@@ -3187,7 +3187,10 @@ public:
     UPPC_NonTypeTemplateParameterType,
 
     /// \brief The type of an exception.
-    UPPC_ExceptionType
+    UPPC_ExceptionType,
+    
+    /// \brief Partial specialization.
+    UPPC_PartialSpecialization
   };
 
   /// \brief If the given type contains an unexpanded parameter pack,
@@ -3245,6 +3248,16 @@ public:
                                        TemplateName Template,
                                        UnexpandedParameterPackContext UPPC);
 
+  /// \brief If the given template argument contains an unexpanded parameter 
+  /// pack, diagnose the error.
+  ///
+  /// \param Arg The template argument that is being checked for unexpanded 
+  /// parameter packs.
+  ///
+  /// \returns true if an error ocurred, false otherwise.
+  bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg,
+                                       UnexpandedParameterPackContext UPPC);
+  
   /// \brief Collect the set of unexpanded parameter packs within the given
   /// template argument.  
   ///
index ce0132ee81416acbe93ed18881efed5ccd985c0f..6384e53e80b1faff55add8936d71ed38f32ce4ae 100644 (file)
@@ -4126,6 +4126,12 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec,
   TemplateArgs.setRAngleLoc(RAngleLoc);
   translateTemplateArguments(TemplateArgsIn, TemplateArgs);
 
+  // Check for unexpanded parameter packs in any of the template arguments.
+  for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
+    if (DiagnoseUnexpandedParameterPack(TemplateArgs[I], 
+                                        UPPC_PartialSpecialization))
+      return true;
+  
   // Check that the template argument list is well-formed for this
   // template.
   llvm::SmallVector<TemplateArgument, 4> Converted;
index 030a0423f74b80c63670b2be1f4125f34fad3835..828d2a3539e447799f41969e72cedb7a79e2e20b 100644 (file)
@@ -263,6 +263,20 @@ bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation Loc,
   return true;
 }
 
+bool Sema::DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg,
+                                         UnexpandedParameterPackContext UPPC) {
+  if (Arg.getArgument().isNull() || 
+      !Arg.getArgument().containsUnexpandedParameterPack())
+    return false;
+  
+  llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
+  CollectUnexpandedParameterPacksVisitor(Unexpanded)
+    .TraverseTemplateArgumentLoc(Arg);
+  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
+  DiagnoseUnexpandedParameterPacks(*this, Arg.getLocation(), UPPC, Unexpanded);
+  return true;  
+}
+
 void Sema::collectUnexpandedParameterPacks(TemplateArgument Arg,
                    llvm::SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) {
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
index 47581fee90a48c0e50fac11b17fe72a6493503be..d52d9c52a4149cc4f58e3ea608607d1fc959c46f 100644 (file)
@@ -211,10 +211,10 @@ struct TestUnexpandedDecls : T{
 
 // FIXME: Test for unexpanded parameter packs in each of the statements.
 
-// FIXME: Once we have template argument deduction, we can test
-// unexpanded parameter packs in partial specializations.
-// template<typename ...Types>
-// struct TestUnexpandedDecls<int, Types>;
+// Test unexpanded parameter packs in partial specializations.
+
+template<typename ...Types>
+struct TestUnexpandedDecls<int, Types>; // expected-error{{partial specialization contains unexpanded parameter pack 'Types'}}
 
 // Test for diagnostics in the presence of multiple unexpanded
 // parameter packs.