[SERVER-62498] Compilation error with LWG-2774 Created: 11/Jan/22  Updated: 29/Oct/23  Resolved: 05/Apr/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 6.0.0-rc0

Type: Bug Priority: Major - P3
Reporter: Casey Carter Assignee: Blake Oler
Resolution: Fixed Votes: 0
Labels: Bug
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

Build the server and run tests with a C++ implementation that implements the resolution of LWG-2774. I'm not certain if any released compiler yet does so: recent GCC may, MSVC won't ship until Visual Studio 2022 version 17.2 preview 2. If you're especially motivated, you could install the most recent VS preview, build https://GitHub.com/microsoft/STL, and build a server with those development STL bits.

In any case, there's an open PR at https://github.com/mongodb/mongo/pull/1437 with the two-line backwards-compatible fix.

Sprint: Service Arch 2022-03-07, Service Arch 2022-03-21, Service Arch 2022-04-04, Service Arch 2022-04-18
Participants:

 Description   

 

WG21 recently approved a change to std::function in the C++ standard library as the resolution of LWG issue 2774. As a result, the previous constructor signature:

template <class F>
function(F fn);

was replaced by:

 

 

template <class F>
function(F&& fn);

 

With the 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<unique_function<T>, std::function<T>> changes from false to true when Standard Libraries implement LWG-2774. MSVC recently implemented this LWG issue in microsoft/STL#2098 and noticed the unique_function test failing as a result.



 Comments   
Comment by Githook User [ 04/Apr/22 ]

Author:

{'name': 'Casey Carter', 'email': 'cacarter@microsoft.com', 'username': 'CaseyCarter'}

Message: 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<unique_function<T>, std::function<T>>` 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 <blake.oler@mongodb.com> and Billy Donahue <billy.donahue@mongodb.com>
Branch: master
https://github.com/mongodb/mongo/commit/6fe4ec2625b638abb709a002c765d23cfe9e4fd6

Comment by Billy Donahue [ 11/Jan/22 ]

This PR looks good to me.

Comment by Kelsey Schubert [ 11/Jan/22 ]

Thanks for the pull request, we'll take a look!

Generated at Thu Feb 08 05:55:18 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.