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

[temp.deduct] The substitution in deduction process that results failure should also apply to class templates CWG2054 #5453

Open
xmh0511 opened this issue May 6, 2022 · 1 comment

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented May 6, 2022

In the current draft, all interpretations of the deduction failures that occur in the deduction of template arguments for class templates want to refer to [temp.deduct] subclause. However, amount of rules defined in [temp.deduct] hints that they are just defined for function templates. partially cite them out here

The resulting substituted and adjusted function type is used as the type of the function template for template argument deduction. ... If the substitution results in an invalid type, as described above, type deduction fails.

If type deduction has not yet failed, then all uses of template parameters in the function type are replaced with the corresponding deduced or default argument values. If the substitution results in an invalid type, as described above, type deduction fails.

Only invalid types and expressions in the immediate context of the function type, its template parameter types, and its explicit-specifier can result in a deduction failure.

The deduction failure can occur in the deduction of template arguments of a class template, especially the deduction for partial specialization. Consider this case

template<class T, class U = void>
struct A{};

/* int fun(...); */
template<class T>
struct A<T, decltype((void)fun(T{}))>{};

int main(){
   A<int> a;
}

[temp.spec.partial.match] p2

A partial specialization matches a given actual template argument list if the template arguments of the partial specialization can be deduced from the actual template argument list, and the deduced template arguments satisfy the associated constraints of the partial specialization, if any.

If it had not an appropriate fun, the substitution would result in an invalid expression, which causes the deduction failure. The cross-reference of deduce wants to borrow the rules defined for function templates. However, as pointed out above. The deduction failures only apply to function templates. A suggestion is that we should explicitly say a rewritten function template will be generated associated with the class template in order to make all rules for deductions apply to that context.

@frederick-vs-ja
Copy link
Contributor

This is CWG2054.

@jensmaurer jensmaurer changed the title [temp.deduct] The substitution in deduction process that results failure should also apply to class templates [temp.deduct] The substitution in deduction process that results failure should also apply to class templates CWG2054 May 6, 2022
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