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

Template parameter pack that does not participate in template argument deduction #4555

Open
xmh0511 opened this issue Mar 23, 2021 · 5 comments
Labels
cwg Issue must be reviewed by CWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking.

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Mar 23, 2021

According to [temp.deduct.call]

Template argument deduction is done by comparing each function template parameter type (call it P) that contains template-parameters that participate in template argument deduction with the type of the corresponding argument of the call (call it A) as described below.

In most cases, the types, templates, and non-type values that are used to compose P participate in template argument deduction.

In this example

template<class...T, class U>
void fun(U);
int main(){
   fun(0);  //#1
}

As per the above rule, the template parameter pack does not participate in template argument deduction. If there were no other special rule specified, as per

if any template argument remains neither deduced nor explicitly specified, template argument deduction fails.

The deduction would fail since the template argument for the template parameter pack is neither deduced(the pack does not participate in the deduction process) nor explicitly specified.

However, in the older standard, there's a special rule states that:

A trailing template parameter pack ([temp.variadic]) not otherwise deduced will be deduced as an empty sequence of template arguments.

However, such a normative rule has become a note in the current draft. I think such a rule should be a normative rule since there's no other alternative rule that states similar things. Making it to be a note is not persuasive to explain why can #1 be otherwise deduced successfully.

@jensmaurer
Copy link
Member

None of the rules you quoted say anything about when a template parameter does or does not participate in template argument deduction, so I'm not seeing your point. (I believe the T pack does participate in template argument deduction here.) Note [temp.deduct.type] p4

In certain contexts, however, the value does not participate in type deduction, but instead uses the values of template arguments that were either deduced elsewhere or explicitly specified.

(Nothing is explicitly specified and this is not a non-deducible context.)

@xmh0511
Copy link
Contributor Author

xmh0511 commented Mar 24, 2021

None of the rules you quoted say anything about when a template parameter does or does not participate in template argument deduction, so I'm not seeing your point. (I believe the T pack does participate in template argument deduction here.) Note [temp.deduct.type] p4

In certain contexts, however, the value does not participate in type deduction, but instead uses the values of template arguments that were either deduced elsewhere or explicitly specified.

(Nothing is explicitly specified and this is not a non-deducible context.)

I think the quote you cited here might apply to such a case:

template<class T>
T fun(T);

In a function call, T in the return type does not participate in template argument deduction, however the second T in function parameter does. Hence it's the case of deduced elsewhere.

In the first snippet, pack T does not appear in function parameters which will be used to determine the value of template arguments in a context of deduction for function call. I think if there's no certain rule rules that "template parameter pack ([temp.variadic]) not otherwise deduced will be deduced as an empty sequence of template arguments", how to deduced the pack to a empty of template arguments?

@jensmaurer
Copy link
Member

jensmaurer commented Mar 24, 2021

So, the point you're making is that the T pack doesn't appear in the function parameters, so template argument deduction can't possibly deduce it. Which means we need wording elsewhere to say what T is in the example above.

The text

A trailing template parameter pack ([temp.variadic]) not otherwise deduced will be deduced as an empty sequence of template arguments.

was made a note in P1787R6.

Asked CWG http://lists.isocpp.org/core/2021/03/10688.php

@jensmaurer jensmaurer reopened this Mar 24, 2021
@jensmaurer jensmaurer added cwg Issue must be reviewed by CWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking. labels Mar 24, 2021
@jensmaurer
Copy link
Member

This seems to be an issue in the wording, but it feels far from editorial.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Mar 25, 2021

So, the point you're making is that the T pack doesn't appear in the function parameters, so template argument deduction can't possibly deduce it. Which means we need wording elsewhere to say what T is in the example above.

The text

A trailing template parameter pack ([temp.variadic]) not otherwise deduced will be deduced as an empty sequence of template arguments.

was made a note in P1787R6.

Asked CWG http://lists.isocpp.org/core/2021/03/10688.php

Yes, That's exactly what I'm concerning here. Moreover, it seems such a case can only apply to those packs that do not parcipate in deduction.

template<class...T>
struct Tuple{
  Tuple(int);
};
template<class...T>
void fun(Tuple<T...>);
int main(){
   fun(0);  //invalid
}

Since it violates [temp.deduct.call#4]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cwg Issue must be reviewed by CWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking.
Projects
None yet
Development

No branches or pull requests

2 participants