From 6fe4ec2625b638abb709a002c765d23cfe9e4fd6 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Thu, 23 Dec 2021 14:56:59 -0800 Subject: SERVER-62498 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. Closes https://github.com/mongodb/mongo/pull/1437 Signed-off-by: Blake Oler and Billy Donahue --- 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 9f353343b69..a680e54a266 100644 --- a/src/mongo/util/functional.h +++ b/src/mongo/util/functional.h @@ -231,6 +231,8 @@ public: // 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: -- cgit v1.2.1