Issue 3238: Insufficiently-defined behavior of std::function deduction guides (original) (raw)
This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++20 status.
3238. Insufficiently-defined behavior of std::function deduction guides
Section: 22.10.17.3.2 [func.wrap.func.con] Status: C++20 Submitter: Louis Dionne Opened: 2019-07-17 Last modified: 2021-02-25
Priority: Not Prioritized
View all other issues in [func.wrap.func.con].
View all issues with C++20 status.
Discussion:
The following code is currently undefined behavior:
#include
struct R { }; struct f0 { R operator()() && { return {}; } };
int main() { std::function f = f0{}; }
The reason is that 22.10.17.3.2 [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, ifdecltype(&F::operator())is of the formR(G::*)(A...) _cv_ &_opt_ noexcept_opt_for a class typeG, then the deduced type isfunction<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.
- Modify 22.10.17.3.2 [func.wrap.func.con] as indicated:
template 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 formR(G::*)(A...) _cv_ &_opt_ noexcept_opt_for a class typeGand a sequence of typesA.... In that case,ifthe deduced type isdecltype(&F::operator())is of the formR(G::*)(A...) _cv_&_opt_ noexcept_opt_for a class typeG, thenfunction<R(A...)>.
[2020-02-13; Prague]
LWG improves wording matching Marshall's Mandating paper.
[Status to Immediate on Friday in Prague.]
Proposed resolution:
This wording is relative to N4849.
- Modify 22.10.17.3.2 [func.wrap.func.con] as indicated:
[_Drafting note:_ This edit should be used instead of the corresponding edit in P1460]
template function(F) -> function<_see below_>;-?- Constraints:
&F::operator()is well-formed when treated as an unevaluated operand anddecltype(&F::operator())is of the formR(G::*)(A...) _cv_ &_opt_noexcept_opt_for a class typeG.-12- Remarks:
This deduction guide participates in overload resolution only ifThe deduced type is&F::operator()is well-formed when treated as an unevaluated operand. In that case, ifdecltype(&F::operator())is of the formR(G::*)(A...) _cv_&_opt_ noexcept_opt_for a class typeG, then tfunction<R(A...)>.