Title
Insufficiently-defined behavior of std::function deduction guides
Status
c++20
Section
[func.wrap.func.con]
Submitter
Louis Dionne

Created on 2019-07-17.00:00:00 last changed 45 months ago

Messages

Date: 2020-02-14.15:01:42

Proposed resolution:

This wording is relative to N4849.

  1. Modify [func.wrap.func.con] as indicated:

    [Drafting note: This edit should be used instead of the corresponding edit in P1460]

    template<class F> function(F) -> function<see below>;
    

    -?- Constraints: &F::operator() is well-formed when treated as an unevaluated operand and decltype(&F::operator()) is of the form R(G::*)(A...) cv &opt noexceptopt for a class type G.

    -12- Remarks: This deduction guide participates in overload resolution only if &F::operator() is well-formed when treated as an unevaluated operand. In that case, if decltype(&F::operator()) is of the form R(G::*)(A...) cv &opt noexceptopt for a class type G, then tThe deduced type is function<R(A...)>.

Date: 2020-02-14.15:01:42

[ Status to Immediate on Friday in Prague. ]

Date: 2020-02-15.00:00:00

[ 2020-02-13; Prague ]

LWG improves wording matching Marshall's Mandating paper.

Date: 2020-02-14.08:07:47

The following code is currently undefined behavior:

#include <functional>

struct R { };
struct f0 { R operator()() && { return {}; } };

int main() { std::function f = f0{}; }

The reason is that [func.wrap.func.con]/12 says:

This deduction guide participates in overload resolution only if &F::operator() is well-formed when treated as an unevaluated operand. In that case, if decltype(&F::operator()) is of the form R(G::*)(A...) cv &opt noexceptopt for a class type G, then the deduced type is function<R(A...)>.

However, it does not define the behavior when &F::operator() is well-formed but not of the required form (in the above example it's of the form R(G::*)(A...) &&, which is rvalue-reference qualified instead of optionally-lvalue-reference qualified). libc++'s implementation of the deduction guide SFINAE's out when either &F::operator() is not well-formed, or it is not of the required form. It seems like mandating that behavior in the Standard is the way to go.

Previous resolution [SUPERSEDED]:

This wording is relative to N4820.

  1. Modify [func.wrap.func.con] as indicated:

    template<class F> function(F) -> function<see below>;
    

    -12- Remarks: This deduction guide participates in overload resolution only if &F::operator() is well-formed when treated as an unevaluated operand, and its type is of the form R(G::*)(A...) cv &opt noexceptopt for a class type G and a sequence of types A.... In that case, if decltype(&F::operator()) is of the form R(G::*)(A...) cv &opt noexceptopt for a class type G, then the deduced type is function<R(A...)>.

History
Date User Action Args
2021-02-25 10:48:01adminsetstatus: wp -> c++20
2020-02-24 16:02:59adminsetstatus: immediate -> wp
2020-02-14 15:01:42adminsetstatus: new -> immediate
2020-02-14 15:01:42adminsetmessages: + msg11126
2020-02-14 15:01:42adminsetstatus: new -> new
2020-02-14 08:07:47adminsetstatus: immediate -> new
2020-02-14 08:07:47adminsetmessages: + msg11101
2019-07-28 15:43:50adminsetmessages: + msg10522
2019-07-17 00:00:00admincreate