Skip to content
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

Fix msvc unreachable code warnings #1841

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kramermt
Copy link

@kramermt kramermt commented Dec 5, 2024

Fixes #1762 and fixes #1814 .

MSVC's __assume(false) results in 4702: unreachable code warnings when used as as the first expression in a comma-sequenced return statement (as in variant_visit_'s return (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 prior return (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 of RANGES_ASSUME()'s conditional use of __builtin_unreachable(). Both compilers still require that a return operation be present after RANGES_ASSUME(false)'s invocation of their __builtin_unreachable() intrinsic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MSVC warning C4702: unreachable code with NDEBUG error warning when compile?
1 participant