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

MSVC warning C4702: unreachable code with NDEBUG #1814

Open
mmaulwurff opened this issue Mar 27, 2024 · 0 comments
Open

MSVC warning C4702: unreachable code with NDEBUG #1814

mmaulwurff opened this issue Mar 27, 2024 · 0 comments

Comments

@mmaulwurff
Copy link

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.
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

No branches or pull requests

1 participant