[SERVER-62480] Fix future_test files in MSVC 2022 under C++20 Created: 10/Jan/22  Updated: 29/Oct/23  Resolved: 13/Jan/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.3.0

Type: Bug Priority: Major - P3
Reporter: Billy Donahue Assignee: Billy Donahue
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-62547 pip: Allow pywin32/pypiwin32 packages... Closed
is depended on by SERVER-62234 Add support for MSVS 2022 builds in C... Closed
is depended on by SERVER-62236 Address novel warnings produced when ... Closed
Problem/Incident
causes SERVER-62564 MSVC2022 enable the /Zc:lambda proces... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Service Arch 2022-1-24
Participants:
Linked BF Score: 70

 Description   

figure out what's wrong with MSVC 2022 in C++20 mode.
It chokes on some lambdas in the future_test files in BF-23951.



 Comments   
Comment by Billy Donahue [ 13/Jan/22 ]

Fortunately Microsoft is already investigating this issue.

https://developercommunity.visualstudio.com/t/lambda-call-triggers-C2440-with-VS1700/1556925

Comment by Billy Donahue [ 13/Jan/22 ]

Minimal Repro:

  • The user-defined move constructor on X is significant.
  • There is no failure if inner lambda is given a ->void trailing return type. It's significant that the inner lambda's return type is deduced.
  • There is no failure unless the outer lambda is generic (takes an auto argument).
  • There is no failure unless the /Zc:lambda feature is used, either directly or implicitly through the use of C++20.

lambda_bug.cpp:

struct X { X(X&&) = default; };
void lambdaBug() {
    [](auto) { (void)[](X){}; }(0);
}

Result:

 
 
Z:\mongo>"C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.30.30705\bin\Hostx64\x64\cl.exe" /c lambda_bug.cpp /Zc:lambda
Microsoft (R) C/C++ Optimizing Compiler Version 19.30.30706 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.
 
lambda_bug.cpp
lambda_bug.cpp(6): error C2440: 'return': cannot convert from 'void (__cdecl *)(X)' to 'lambdaBug::<lambda_1>::()::<lambda_1>::<lambda_typedef_cdecl>'
lambda_bug.cpp(6): note: This conversion requires a reinterpret_cast, a C-style cast or function-style cast
lambda_bug.cpp(6): note: see reference to function template instantiation 'auto lambdaBug::<lambda_1>::operator ()<int>(_T1) const' being compiled
        with
        [
            _T1=int
        ]
lambda_bug.cpp(6): error C2440: 'return': cannot convert from 'void (__vectorcall *)(X)' to 'lambdaBug::<lambda_1>::()::<lambda_1>::<lambda_typedef_vectorcall>'
lambda_bug.cpp(6): note: This conversion requires a reinterpret_cast, a C-style cast or function-style cast

Comment by Billy Donahue [ 13/Jan/22 ]

Reopening to spend a little time on getting a minimal repro so we can report this upstream.

Comment by Githook User [ 13/Jan/22 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-62564 Trailing return types in complex lambdas in future_test_*

Revert "SERVER-62480 disable new lambda processor in MSVC2022 C++20 mode"
This reverts commit cf0d1ffe36d1d787169569989abefa6cbdb2e163.
Branch: master
https://github.com/mongodb/mongo/commit/f212fff6d910cd717e2a7979ed51687d0fb4832a

Comment by Githook User [ 13/Jan/22 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-62480 disable new lambda processor in MSVC2022 C++20 mode
Branch: master
https://github.com/mongodb/mongo/commit/a632623f2e86e8e71104d43481a85b695a0c21b6

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