You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C:\builds\eprotect-platfrom\auth\client\include\nonstd\expected.hpp(2142) : error C2220: the following warning is treated as an error
C:\builds\eprotect-platfrom\auth\client\include\nonstd\expected.hpp(2142) : warning C4702: unreachable code
#include "expected.hpp"
int main()
{
nonstd::expected<int, int> ei = 0;
return ei.value();
}
Compile using cl /O2 /W4 /WX main.cpp. expected-lite version is 0.6.3.
Output:
Microsoft (R) C/C++ Optimizing Compiler Version 19.39.33523 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
main.cpp
C:\test\expected.hpp(1803) : error C2220: the following warning is treated as an error
C:\test\expected.hpp(1803) : warning C4702: unreachable code
Ah, at first I thought line 2142 is with the 0.6.3 release branch, but apparently it's on master, so there is actual code there. So the correct reference is
Maybe MSVC doesn't like the value() call next to the comma operator after rethrow, which is actually unreachable. Maybe a random throw expression instead of value() call would silence it, but I can't test this now.
A few other wrong ideas I had:
immediately invoked lambda that calls rethrow, and lies about its return type. That would produce another warning about the function not returning anything, because rethrow is not actually throwing.
changing rethrow to lie that its return type is value_type&. That would generate a similar warning inside rethrow, because it doesn't return that type, nor does it throw. assert and RaiseException look like normal function calls to the control flow analyzer.
change to an if statement. This wouldn't work with C++11 compilers in constexpr context.
Activity
subbota-a commentedon Mar 21, 2024
Me too
szaszm commentedon Apr 23, 2024
How does that work? That line is a comment, there is no code there: https://github.com/martinmoene/expected-lite/blob/v0.6.3/include/nonstd/expected.hpp#L2142
Is it any different in your build directory?
np-c0mp1ete commentedon May 22, 2024
Hello!
Repro:
Compile using
cl /O2 /W4 /WX main.cpp. expected-lite version is 0.6.3.Output:
martinmoene commentedon May 29, 2024
On Compiler Explorer:
-O2 -W4 -WX -Dnsel_CONFIG_SELECT_EXPECTED=nsel_EXPECTED_NONSTD: C4702: unreachable code.-O2 -Wall -Wunreachable-code-aggressive -Dnsel_CONFIG_SELECT_EXPECTED=nsel_EXPECTED_NONSTD: no warning.I'm not sure what to think of MSVC's warning.
szaszm commentedon May 29, 2024
Ah, at first I thought line 2142 is with the 0.6.3 release branch, but apparently it's on master, so there is actual code there. So the correct reference is
Maybe MSVC doesn't like the
value()call next to the comma operator afterrethrow, which is actually unreachable. Maybe a randomthrowexpression instead ofvalue()call would silence it, but I can't test this now.A few other wrong ideas I had:
rethrow, and lies about its return type. That would produce another warning about the function not returning anything, becauserethrowis not actually throwing.rethrowto lie that its return type isvalue_type&. That would generate a similar warning insiderethrow, because it doesn't return that type, nor does itthrow.assertandRaiseExceptionlook like normal function calls to the control flow analyzer.ifstatement. This wouldn't work with C++11 compilers inconstexprcontext.martinmoene commentedon May 30, 2024
Thanks for your helpful thoughts to advance this issue.
Fix (locally disable) MSVC warning C4702: unreachable code (#65, thanks
Release 0.7.0