cplusplus / CWG

Core Working Group
24 stars 7 forks source link

[temp.deduct.general]/note-3 The note is a bit misleading #275

Open xmh0511 opened 1 year ago

xmh0511 commented 1 year ago

Full name of submitter (unless configured in github; will be published with the issue): Jim X

[temp.deduct.general]/note-3 says:

Overload resolution will check the other parameters, including parameters with dependent types in which no template parameters participate in template argument deduction

Anyway, such a parameter should make the deduction fail, this means, overload resolution won't further check it. The [temp.deduct.type] p19 says:

Template parameters do not participate in template argument deduction if they are used only in non-deduced contexts.

[temp.deduct.type] p4 says:

If a template parameter is used only in non-deduced contexts and is not explicitly specified, template argument deduction fails.

For such a template parameter, either it is explicitly specified or obtained from the default argument. Otherwise, it is a deduction failure.

frederick-vs-ja commented 1 year ago

IIUC the note is talking about such cases:

template<class T>
void f(T, std::type_identity_t<T>);

int main()
{
    f(42, 0.0);
}

In this example, T participates in template argument deduction in the first function parameter, but not in the second one.

I think the note can be delicately reworded, but this should be an editorial issue.

jensmaurer commented 1 year ago

Yes. Note the "only"; a template parameter may be deducible from one parameter but appear only in non-deduced contexts in another parameter. The note highlights the checking in overload resolution for the other parameter.

I'm not seeing a defect here.

xmh0511 commented 1 year ago

a template parameter may be deducible from one parameter but appear only in non-deduced contexts in another parameter.

if this is the case, we won't say "no template parameters participate in template argument deduction". For example

template<class T>
void f(T, std::type_identity_t<T>);

We won't say T does not participate in template argument deduction. This is clear specified in [temp.deduct.type] p19

Template parameters do not participate in template argument deduction if they are used only in non-deduced contexts.

Hence, for this sentence

parameters with dependent types in which no template parameters participate in template argument deduction

This implies that these template parameters in the parameter appear only in the non-deduced contexts. Obviously, template<class T> void f(T, std::type_identity_t<T>); where T is not the case.

jensmaurer commented 1 year ago

Ok, so the problem is that "do not participate in template argument deduction" has too broad a scope (because it covers the entire template declaration, not just deduction from a single function parameter).

What if the note said "in which no template parameters participate in template argument deduction" -> "in which no template parameters appear in a deducible context" ?

xmh0511 commented 1 year ago

"in which no template parameters appear in a deducible context"

Does this imply this case?

template<class T, class U>
void f(T, std::type_identity_t<U>);

However, the case is considered as deduction fails as per [temp.deduct.type] p4. Overload resolution won't further check it.

jensmaurer commented 1 year ago

This is a note. It doesn't need to be exhaustive. Obviously, overload resolution won't check anything if the process bails out before (e.g. due to deduction failure).

xmh0511 commented 1 year ago

This is a note. It doesn't need to be exhaustive. Obviously, overload resolution won't check anything if the process bails out before (e.g. due to deduction failure).

I think we should remove "parameters with dependent types in which no template parameters participate in template argument deduction" from the note. The intended meaning should be:

parameters with dependent types where the template parameters are in the non-deduced contexts but their values can be obtained from other pairs.

This is too long. As this is just a note, hence remove it to avoid further misleading is a trade-off way.