]> granicus.if.org Git - clang/commitdiff
Parameter packs can't have default arguments.
authorAnders Carlsson <andersca@mac.com>
Fri, 12 Jun 2009 22:30:13 +0000 (22:30 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 12 Jun 2009 22:30:13 +0000 (22:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73262 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaTemplate.cpp
test/SemaTemplate/variadic-class-template-1.cpp [new file with mode: 0644]

index 899fd768dcaa17a9065ceda1afcb28bc360d1c88..865b1ce4f3c92408ef3c1cdb7ecb4bde47d0b5a1 100644 (file)
@@ -833,6 +833,10 @@ def err_template_kw_refers_to_non_template : Error<
 def err_template_kw_refers_to_function_template : Error<
     "%0 following the 'template' keyword refers to a function template">;
 
+// C++0x Variadic Templates
+def err_template_param_pack_default_arg : Error<
+  "template parameter pack cannot have a default argument">;
+
 def err_unexpected_typedef : Error<
   "unexpected type name %0: expected expression">;
 def err_unexpected_namespace : Error<
index 8058ad2d63fc68a0bd97ebbe40c4cb44f0d810c8..00d3e54565e266951c26bd919ccf8d2cce56702e 100644 (file)
@@ -187,6 +187,15 @@ void Sema::ActOnTypeParameterDefault(DeclPtrTy TypeParam,
     = cast<TemplateTypeParmDecl>(TypeParam.getAs<Decl>());
   QualType Default = QualType::getFromOpaquePtr(DefaultT);
 
+  // C++0x [temp.param]p9:
+  // A default template-argument may be specified for any kind of
+  // template-parameter that is not a template parameter pack.  
+  if (Parm->isParameterPack()) {
+    Diag(DefaultLoc, diag::err_template_param_pack_default_arg);
+    Parm->setInvalidDecl();
+    return;
+  }
+  
   // C++ [temp.param]p14:
   //   A template-parameter shall not be used in its own default argument.
   // FIXME: Implement this check! Needs a recursive walk over the types.
diff --git a/test/SemaTemplate/variadic-class-template-1.cpp b/test/SemaTemplate/variadic-class-template-1.cpp
new file mode 100644 (file)
index 0000000..b811423
--- /dev/null
@@ -0,0 +1,3 @@
+// RUN: clang-cc -fsyntax-only -verify %s -std=c++0x
+
+template<typename... Args = int> struct S { }; // expected-error{{template parameter pack cannot have a default argument}}