From: Douglas Gregor Date: Thu, 21 Oct 2010 17:26:49 +0000 (+0000) Subject: Diagnose the declaration of template template parameters that X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=369ea27b56b89379023366ff1b8ab362b5709e4e;p=clang Diagnose the declaration of template template parameters that themselves have no template parameters. This is actually a restriction due to the grammar of template template parameters, but we choose to diagnose it in Sema to provide better recovery. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117032 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 87d2a9f81f..17a585896b 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1386,6 +1386,8 @@ def err_template_parameter_default_template_member : Error< "class template">; def err_template_parameter_default_friend_template : Error< "default template argument not permitted on a friend template">; +def err_template_template_parm_no_parms : Error< + "template template parameter must have its own template parameters">; def err_template_variable : Error<"variable %0 declared as a template">; def err_template_variable_noparams : Error< diff --git a/lib/Parse/ParseTemplate.cpp b/lib/Parse/ParseTemplate.cpp index 8142cd226b..c472972e5c 100644 --- a/lib/Parse/ParseTemplate.cpp +++ b/lib/Parse/ParseTemplate.cpp @@ -540,7 +540,7 @@ Parser::ParseTemplateTemplateParameter(unsigned Depth, unsigned Position) { TemplateParamsTy *ParamList = Actions.ActOnTemplateParameterList(Depth, SourceLocation(), TemplateLoc, LAngleLoc, - &TemplateParams[0], + TemplateParams.data(), TemplateParams.size(), RAngleLoc); diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index cd67955a22..95b2223658 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -666,7 +666,7 @@ Decl *Sema::ActOnTemplateTemplateParameter(Scope* S, TemplateTemplateParmDecl::Create(Context, Context.getTranslationUnitDecl(), NameLoc.isInvalid()? TmpLoc : NameLoc, Depth, Position, Name, - (TemplateParameterList*)Params); + Params); // If the template template parameter has a name, then link the identifier // into the scope and lookup mechanisms. @@ -694,6 +694,11 @@ Decl *Sema::ActOnTemplateTemplateParameter(Scope* S, Param->setDefaultArgument(DefaultArg, false); } + if (Params->size() == 0) { + Diag(Param->getLocation(), diag::err_template_template_parm_no_parms) + << SourceRange(Params->getLAngleLoc(), Params->getRAngleLoc()); + Param->setInvalidDecl(); + } return Param; } diff --git a/test/CXX/temp/temp.param/p1.cpp b/test/CXX/temp/temp.param/p1.cpp index 676bffe31d..edc99733f0 100644 --- a/test/CXX/temp/temp.param/p1.cpp +++ b/test/CXX/temp/temp.param/p1.cpp @@ -1,4 +1,6 @@ // Suppress 'no run line' failure. -// RUN: echo ok +// RUN: %clang_cc1 -fsyntax-only -verify %s + +template class C> class D; // expected-error{{template template parameter must have its own template parameters}} + -// Paragraph 1 is descriptive, and therefore requires no tests.