range-v3
range-v3 copied to clipboard
MSVC warning C4702: unreachable code with NDEBUG
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:
- 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? - 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.