ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.06k stars 437 forks source link

error warning when compile? #1762

Closed dangdkhanh closed 4 months ago

dangdkhanh commented 1 year ago

Hi, i am using vs22 and range-v3 latest version. I recently noticed this rather annoying warning. i'm not sure where it came from though tried omitting range-v3 headers in turn but it still shows up. everything is working fine but i still hope to be able to fix it.

2>C:\Dev\vcpkg\installed\x64-windows\include\range\v3\detail\variant.hpp(342): error C2220: the following warning is treated as an error
2>C:\Dev\vcpkg\installed\x64-windows\include\range\v3\detail\variant.hpp(342): error C2220: the following warning is treated as an error
2>C:\Dev\vcpkg\installed\x64-windows\include\range\v3\detail\variant.hpp(342): error C2220: the following warning is treated as an error
2>C:\Dev\vcpkg\installed\x64-windows\include\range\v3\detail\variant.hpp(342): warning C4702: unreachable code
2>C:\Dev\vcpkg\installed\x64-windows\include\range\v3\detail\variant.hpp(342): warning C4702: unreachable code
2>C:\Dev\vcpkg\installed\x64-windows\include\range\v3\detail\variant.hpp(342): warning C4702: unreachable code

image

Thanks you.

przemkovv commented 10 months ago

The following code can reproduce the issue:

auto test = ranges::views::generate_n(rand, 5) | ranges::to<std::vector>();

and compiling in MSVC in the release mode (in debug, it is not an issue).

A workaround is to wrap conversion.hpp header with pragma disabling warning:

#pragma warning(push)
#pragma warning(disable : 4702)
#include <range/v3/range/conversion.hpp>
#pragma warning(pop)