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

MSVC warning C4702: unreachable code with NDEBUG

Open mmaulwurff opened this issue 10 months ago • 0 comments

The symptom is the same as in #1762. The solution proposed there (silencing the warning) is not always suitable.

range-v3: v0.12.0 and latest master (commit 53c40dd).

Compiler: MSVC 19.37.32825.0, also checked on latest MSVC with Compiler Explorer.

Compiler parameters: /std:c++20 /W4 /DNDEBUG

Code that triggers the warning (simplified from real life code):

#include <ranges>
#include <vector>

#include <range/v3/range/conversion.hpp>

int main()
{
    const std::vector<std::vector<int>> v{{{1, 2, 3}}, {{4, 5, 6}}};
    v | std::views::transform([](const auto & v){ return v; }) | std::views::join | ranges::to_vector;
}

(run)

C:\data\libraries\installed\x64-windows\include\range\v3\detail\variant.hpp(342) : warning C4702: unreachable code
C:\data\libraries\installed\x64-windows\include\range\v3\detail\variant.hpp(342) : warning C4702: unreachable code
C:\data\libraries\installed\x64-windows\include\range\v3\detail\variant.hpp(342) : warning C4702: unreachable code

It looks like that "transform-join-to_vector" sequence causes the warning. The same code without transform or join doesn't yield the warning.

This issue represents two problems:

  1. Correctness. It's unclear if the instantiated problematic code return (RANGES_EXPECT(false), 0); is ever executed. Are there any circumstances when this RANGE_EXPECT may fire? Is the code like in the example incorrect?
  2. Build. Building the code with and without NDEBUG has different results in terms of warnings. It would be more convenient to software developer to have the same amount or more of warnings in debug mode than in release mode.

mmaulwurff avatar Mar 27 '24 04:03 mmaulwurff