Fix msvc unreachable code warnings #1841
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1762 and fixes #1814 .
MSVC's
__assume(false)
results in4702: unreachable code
warnings when used as as the first expression in a comma-sequenced return statement (as invariant_visit_
'sreturn (RANGES_EXPECT(false), 0);
.This PR adds a
RANGES_EXPECT_UNREACHABLE_RETURN(RETURN_VALUE)
macro to be used in these cases, which expands to solely the__assume(false);
in MSVC release builds; otherwise expands to the priorreturn (RANGES_EXPECT(false), RETURN_VALUE);
value.note: gcc no longer implements
-Wunreachable-code
and clang can produce unreachable code warnings, but not in the case ofRANGES_ASSUME()
's conditional use of__builtin_unreachable()
. Both compilers still require that areturn
operation be present afterRANGES_ASSUME(false)
's invocation of their__builtin_unreachable()
intrinsic.