Skip to content

[tem.param] Template heads of concept definitions #951

Description

@cor3ntin

If a template-parameter of a class template, variable template, or alias template has a default template argument, each subsequent template-parameter shall either have a default template argument supplied or declare a template parameter pack. If a template-parameter of a primary class template, primary variable template, or alias template declares a template parameter pack, it shall be the last template-parameter.

Per this logic, all of these are valid concept definitions.

template <typename T, typename U = int, typename V>
concept C = true;

template <typename T = int>
concept C2 = true;
static_assert(C2<>);

template <typename... T, typename... U>
concept C3 = true;


template <typename... T, typename U = int>
concept C4 = true;


template <typename... T, typename U>
concept C5 = true;

There is wild implementation divergence https://compiler-explorer.com/z/z376fMYYr

Additionally, the C2 case is interesting.

in [concept.definition] we say:

The first declared template parameter of a concept definition is its prototype parameter

But can that parameter be defaulted?

I assume we want none of these examples to be valid.

Suggested resolution

Modify the last paragraph of [temp.concept]

The first declared template parameter of a concept definition is its prototype parameter. It shall not have a default argument [temp.param]. A type concept is a concept whose prototype parameter is a type template parameter.

Modify [temp.param]/p19

If a template-parameter of a class template, variable template, concept, or alias template has a default template argument, each subsequent template-parameter shall either have a default template argument supplied or declare a template parameter pack. If a template-parameter of a primary class template, primary variable template, concept, or alias template declares a template parameter pack, it shall be the last template-parameter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions