-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iostreams\detail\streambuf\indirect_streambuf.hpp(440) : warning C4702: unreachable code #138
Comments
I'm not seeing how that code is unreachable. Can you post more info?
|
This code is unreachable under at least some versions of MSVC (14.36 but not 14.35) if shared_buffer() returns false, only with certain combinations of settings. A minimal repro with MSVC 14.36 is simply:
Starting from an empty project's Release configuration, only the following changes from the default project settings are needed:
Since filtering_ostream's category/mode is 'output', the condition on line 438 will always be false, and both 439 and 440 would be unreachable. Curiously, the warning is on line 440 (setg), not line 439 (immediately after the condition). I wonder if the internal mechanism doesn't have directly to do with shared_buffer always returning false due to the trait checks, but rather something about line 439 - perhaps it's seen by the compiler as always throwing, or something like that. We also see little choice but to use the pragma workaround mentioned by OP. |
Submitted a VS feedback item here: https://developercommunity.visualstudio.com/t/Unexpected-C4702-Unreachable-code-in-boo/10410775 |
This warning has been observed under more than one version. One specific example, as described in issue boostorg#138, is on indirect_streambuf.hpp(440) when Whole Program Optimization is off. In this case, the line before is seen by the optimizer as always throwing for particular instantiations of the template, and therefore the line in question is flagged as not reachable. MSVC team has stated this is is expected behavior. This is a simple and hopefully good-enough fix.
This warning has been observed under more than one version. One specific example, as described in issue #138, is on indirect_streambuf.hpp(440) when Whole Program Optimization is off. In this case, the line before is seen by the optimizer as always throwing for particular instantiations of the template, and therefore the line in question is flagged as not reachable. MSVC team has stated this is is expected behavior. This is a simple and hopefully good-enough fix.
hi,
i'm compiling my .dll code for release without optimization (/W3 /WX /MD /Od) and msvc reports warning (error in my case):
boost-1.77.0\include\boost\iostreams\detail\streambuf\indirect_streambuf.hpp(440) : error C2220: the following warning is treated as an error
boost-1.77.0\include\boost\iostreams\detail\streambuf\indirect_streambuf.hpp(440) : warning C4702: unreachable code
as a local workaround i've added following pragma to disable_warnings.hpp
pragma warning(disable:4702) // Unreachable code
The text was updated successfully, but these errors were encountered: