Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CWG2994 [temp.param] Unintentional restrictions on parameters packs which are also pack expansions #666

Open
Eisenwave opened this issue Jan 20, 2025 · 2 comments

Comments

@Eisenwave
Copy link
Collaborator

Eisenwave commented Jan 20, 2025

Reference (section label): [temp.param] paragraph 14

Issue description

There is implementation divergence in the following example:

template <class Head, class... Tail>
struct test {
    template <Tail..., Head>
    static void make() { } // MSVC error C3547: template parameter 'unnamed-parameter' cannot be used
                           // because it follows a template parameter pack and
                           // cannot be deduced from the function parameters of 'test<Head,Tail...>::make'
};

int main() {
    test<char, int, float>::make<4, 6.f, 'a'>();
}

Clang permits this example, but MSVC abides by [temp.param] paragraph 14, sentence 3:

A template parameter pack of a function template shall not be followed by another template parameter unless that template parameter can be deduced from the parameter-type-list ([dcl.fct]) of the function template or has a default argument ([temp.deduct]).

The intent of the restriction is that it is not permitted to write template parameter lists for which it is impossible to provide all arguments. However, [temp.param] paragraph 17 states that Tail... is not just a parameter pack but also a pack expansion. Considering that it expands to int, float in this example, following this restriction literally is nonsensical; it is clearly possible to provide (non-type) template-arguments to test<char, int, float>::make because it accepts exactly three.

Suggested resolution

Update [temp.param] paragraph 14 as follows:

A template parameter pack of a function template shall not be followed by another template parameter P unless
  • that template parameter P can be deduced from the parameter-type-list ([dcl.fct]) of the function template, or
  • P has a default argument ([temp.deduct]), or
  • that template parameter pack is also a pack expansion.
@Eisenwave
Copy link
Collaborator Author

On a side note, this area of GCC has been bugged for a long time; see https://stackoverflow.com/q/79364196/5740428, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84796

@Eisenwave Eisenwave changed the title [temp.param] Clarify how many template-arguments correspond to a template parameter pack which is also an expansion [temp.param] Unintentional restrictons on parameters packs which are also pack expansions Jan 20, 2025
@Eisenwave Eisenwave changed the title [temp.param] Unintentional restrictons on parameters packs which are also pack expansions [temp.param] Unintentional restrictions on parameters packs which are also pack expansions Jan 20, 2025
@jensmaurer
Copy link
Member

CWG2994

@jensmaurer jensmaurer changed the title [temp.param] Unintentional restrictions on parameters packs which are also pack expansions CWG2994 [temp.param] Unintentional restrictions on parameters packs which are also pack expansions Feb 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants