Skip to content

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

Description

@xmh0511

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.

Activity

  1. frederick-vs-ja commented on May 6, 2022

    @frederick-vs-ja
    Contributor

    This is CWG2054.

  2. 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[/+] on May 6, 2022
  3. frederick-vs-ja commented on May 18, 2025

    @frederick-vs-ja
    Contributor

    Fixed by #6684 (e6a9da6).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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