range-v3 icon indicating copy to clipboard operation
range-v3 copied to clipboard

Fix msvc unreachable code warnings

Open kramermt opened this issue 11 months ago • 1 comments

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.

kramermt avatar Dec 05 '24 01:12 kramermt

@CaseyCarter , any steps I can take to help advance this PR?

kramermt avatar Jan 14 '25 01:01 kramermt