Title
Implicit deduction guides should propagate constraints
Status
drwp
Section
12.2.2.9 [over.match.class.deduct]
Submitter
Roy Jacobson

Created on 2022-09-11.00:00:00 last changed 2 weeks ago

Messages

Date: 2023-10-20.21:07:14

Proposed resolution (approved by CWG 2023-10-20):

Change in 12.2.2.9 [over.match.class.deduct] bullet 1.1 as follows:

  • If C is defined, for each constructor of C, a function template with the following properties:
    • The template parameters are the template parameters of C followed by the template parameters (including default template arguments) of the constructor, if any.
    • The associated constraints (13.5.3 [temp.constr.decl]) are the conjunction of the associated constraints of C and the associated constraints of the constructor.
    • The types of the function parameters are those of the constructor.
    • The return type is the class template specialization designated by C and template arguments corresponding to the template parameters of C.
Date: 2023-11-15.00:00:00

[Accepted as a DR at the November, 2023 meeting.]

Consider:

template<class T> concept True = true;

template<class T> struct X {
  template<class U> requires True<T> X(T, U(&)[3]);
};
template<typename T, typename U> X(T, U(&)[3]) -> X<T>;
int arr3[3];
X z(3, arr3);     // #1

According to 12.2.2.9 [over.match.class.deduct] bullet 1.1, the requires-clause of the constructor is not propagated to the function template synthesized for the implicit deduction guide. Thus, instead of favoring the more-constrained implicit deduction guide per 12.2.4.1 [over.match.best.general] bullet 2.6, the user-declared deduction-guide is preferred per 12.2.4.1 [over.match.best.general] bullet 2.11.

History
Date User Action Args
2024-04-05 21:43:46adminsetstatus: dr -> drwp
2023-12-19 10:15:28adminsetstatus: ready -> dr
2023-11-10 14:27:11adminsetstatus: tentatively ready -> ready
2023-10-20 21:07:14adminsetmessages: + msg7468
2023-10-20 21:07:14adminsetstatus: open -> tentatively ready
2022-09-11 00:00:00admincreate