From 93f64934e9a40977b81569c145edd31e51bf6420 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Thu, 23 Dec 2021 14:56:59 -0800 Subject: [PATCH] non-`const` `unique_function` should not convert to `std::function` even after LWG-2774 [LWG-2774](https://wg21.link/lwg2774) changes `std::function`'s converting constructor to accept its argument by forwarding reference. With that change implemented, that constructor becomes a better match for non-`const` `unique_function` arguments than `unique_function`'s `const`-qualified deleted conversion operator template to `std::function`. As a result, `std::is_convertible_v, std::function>` changes from `false` to `true` when Standard Libraries implement LWG-2774. (MSVC recently implemented this LWG issue in https://github.com/microsoft/STL/pull/2098 and noticed the `unique_function` test failing as a result.) I believe the fix is to add another deleted conversion operator template that is not `const`-qualified to `unique_function`. This makes the test pass locally, as well as correcting a simplified test case with GCC trunk (https://github.com/microsoft/STL/pull/2098) which I believe also implements LWG-2774. --- src/mongo/util/functional.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mongo/util/functional.h b/src/mongo/util/functional.h index c30089a64e9fe..1673382fa9fcc 100644 --- a/src/mongo/util/functional.h +++ b/src/mongo/util/functional.h @@ -123,6 +123,8 @@ class unique_function { // NOTE: This is not quite able to disable all `std::function` conversions on MSVC, at this // time. template + operator std::function() = delete; + template operator std::function() const = delete; private: