Clang error: template parameter pack must be the last template parameter (err_template_param_pack_must_be_last_template_parameter)
Jump to navigation
Jump to search
Text | error: template parameter pack must be the last template parameter |
---|---|
Type | Error |
Category | Semantic Issue |
Internal Id | err_template_param_pack_must_be_last_template_parameter |
Internal Message | template parameter pack must be the last template parameter
|
Regular Expression | (?:error|fatal error)\: template parameter pack must be the last template parameter
|
First Commit | 2009-06-13 327865db5323 A parameter pack must always come last in a class template. |
Description
Example
Flags | -xc++ -std=c++11
|
|
---|---|---|
Source |
template<typename... Ts, typename U> struct S {}; // Parameter pack not last
int main() {}
| |
Compiler Output |
<source>:1:22: error: template parameter pack must be the last template parameter |
Clang Internals (17.0.6)
Git Commit Message
A parameter pack must always come last in a class template. llvm-svn: 73269
Used in Clang Sources
This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.
clang/lib/Sema/SemaTemplate.cpp (line 3022)
/// Checks the validity of a template parameter list, possibly
/// considering the template parameter list from a previous
/// declaration.
///
/// If an "old" template parameter list is provided, it must be
/// equivalent (per TemplateParameterListsAreEqual) to the "new"
/// template parameter list.
///
/// \param NewParams Template parameter list for a new template
/// declaration. This template parameter list will be updated with any
/// default arguments that are carried through from the previous
/// template parameter list.
///
/// \param OldParams If provided, template parameter list from a
/// previous declaration of the same template. Default template
/// arguments will be merged from the old template parameter list to
/// the new template parameter list.
///
/// \param TPC Describes the context in which we are checking the given
/// template parameter list.
///
/// \param SkipBody If we might have already made a prior merged definition
/// of this template visible, the corresponding body-skipping information.
/// Default argument redefinition is not an error when skipping such a body,
/// because (under the ODR) we can assume the default arguments are the same
/// as the prior merged definition.
///
/// \returns true if an error occurred, false otherwise.
bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, TemplateParameterList *OldParams, TemplateParamListContext TPC, SkipBodyInfo *SkipBody) {
// ...
for (TemplateParameterList::iterator NewParam = NewParams->begin(), NewParamEnd = NewParams->end(); NewParam != NewParamEnd; ++NewParam) {
// ...
// C++11 [temp.param]p11:
// If a template parameter of a primary class template or alias template
// is a template parameter pack, it shall be the last template parameter.
if (SawParameterPack && (NewParam + 1) != NewParamEnd && (TPC == TPC_ClassTemplate || TPC == TPC_VarTemplate || TPC == TPC_TypeAliasTemplate)) {
Diag((*NewParam)->getLocation(), diag::err_template_param_pack_must_be_last_template_parameter);
clang/lib/Sema/SemaTemplate.cpp (line 9015)
Decl *Sema::ActOnConceptDefinition(Scope *S, MultiTemplateParamsArg TemplateParameterLists, IdentifierInfo *Name, SourceLocation NameLoc, Expr *ConstraintExpr) {
// ...
// Ensure that the parameter pack, if present, is the last parameter in the
// template.
for (TemplateParameterList::const_iterator ParamIt = Params->begin(), ParamEnd = Params->end(); ParamIt != ParamEnd; ++ParamIt) {
// ...
if (Param->isParameterPack()) {
// ...
Diag(Param->getLocation(), diag::err_template_param_pack_must_be_last_template_parameter);
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/CXX/temp/temp.param/p11-0x.cpp
- clang/test/CXX/temp/temp.param/p11-0x.cpp:26:22: error: template parameter pack must be the last template parameter
- clang/test/CXX/temp/temp.param/p11-0x.cpp:30:22: error: template parameter pack must be the last template parameter
- clang/test/CXX/temp/temp.param/p11-0x.cpp:34:17: error: template parameter pack must be the last template parameter
- clang/test/CXX/temp/temp.param/p11-0x.cpp:37:17: error: template parameter pack must be the last template parameter
- clang/test/CXX/temp/temp.param/p11-0x.cpp:41:38: error: template parameter pack must be the last template parameter
- clang/test/CXX/temp/temp.param/p11-0x.cpp:44:38: error: template parameter pack must be the last template parameter