diff --git a/xml/issue4256.xml b/xml/issue4256.xml new file mode 100644 index 0000000000..6fcc9dc0db --- /dev/null +++ b/xml/issue4256.xml @@ -0,0 +1,84 @@ + + + + +Incorrect constrains for <code>function_ref</code> constructors from <code>nontype_t</code> +
+Tomasz Kamiński +14 May 2025 +99 + + +

+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)). +

+ +
+ + +

+This wording is relative to . +

+
    + +
  1. Modify as indicated:

    + +
    +
    +template<auto f> constexpr function_ref(nontype_t<f>) noexcept;
    +
    +
    +

    -8- Let F be decltype(f).

    +

    -9- Constraints: is-invocable-using<const F&> is true.

    +[…] +
    + +
    +template<auto f, class U> constexpr function_ref(nontype_t<f>, U&& obj) noexcept;
    +
    +
    +

    -12- Let T be remove_reference_t<U> and F be decltype(f).

    +

    -13- Constraints::

    +
      +
    • (13.1) is_rvalue_reference_v<U&&> is false, and

    • +
    • (13.2) is-invocable-using<const F&, T cv&> is true.

    • +
    +[…] +
    + +
    +template<auto f, class T> constexpr function_ref(nontype_t<f>, T cv* obj) noexcept;
    +
    +
    +

    -17- Let F be decltype(f).

    +

    -16- Constraints: is-invocable-using<const F&, T cv*> is true.

    +[…] +
    +
    + +
  2. +
+ +
+ +