This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
function_ref
constructors from nontype_t
Section: 22.10.17.6.3 [func.wrap.ref.ctor] Status: New Submitter: Tomasz Kamiński Opened: 2025-05-14 Last modified: 2025-05-14
Priority: Not Prioritized
View all issues with New status.
Discussion:
For the following class:
struct M { void operator(); };
The constructor of function_ref<void()>
from nontype_t
is considered to be valid candidate
(is_constructible_v<function_ref<void()>, nontype_t<M{}>> is true
),
despite the fact that the corresponding invocation of template argument object, that is const lvalue,
is ill-formed. As consequence we produce hard error from inside of this constructor.
This is caused by the fact that for constructors with non-type auto f
parameter,
we are checking if is-invocable-using<F>
is true
,
where F
is decltype(f)
i.e. M
for the example.
We should use const F&
or decltype((f))
.
Proposed resolution:
This wording is relative to N5008.
Modify 22.10.17.6.3 [func.wrap.ref.ctor] as indicated:
template<auto f> constexpr function_ref(nontype_t<f>) noexcept;-8- Let
F
bedecltype(f)
.-9- Constraints:
[…]is-invocable-using<const F&>
istrue
.template<auto f, class U> constexpr function_ref(nontype_t<f>, U&& obj) noexcept;-12- Let
T
beremove_reference_t<U>
andF
bedecltype(f)
.-13- Constraints::
[…]
(13.1)
is_rvalue_reference_v<U&&>
is false, and(13.2)
is-invocable-using<const F&, T cv&>
istrue
.template<auto f, class T> constexpr function_ref(nontype_t<f>, T cv* obj) noexcept;-17- Let
F
bedecltype(f)
.-16- Constraints:
[…]is-invocable-using<const F&, T cv*>
istrue
.