ericniebler / range-v3

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

Range-v3 failed to build due to errors C2672 C2893 C2780 and C2783 with MSVC on windows #1203

Closed spacelg closed 5 years ago

spacelg commented 5 years ago

Environment: Windows Server 2016 + VS2017 + Range-v3 master branch latest srouce code.

Range-v3 failed to build due to errors C2672 C2893 C2780 and C2783 with MSVC on windows. It can be first reproduced on master revision f2a3d5f.Could you help have a look about this issue? Thanks in advance!

Steps to reproduce the behavior: 1.git clone https://github.com/ericniebler/range-v3 D:\Range-v3\src 2.Open a VS 2017 x86 command prompt as admin and browse to D:\Range-v3 3.mkdir build_x86 && pushd build_x86 4.cmake -G "Visual Studio 15 2017" -DCMAKE_SYSTEM_VERSION=10.0.17134.0 -DCMAKE_BUILD_TYPE=Release ..\src\ 5.pop 6.pushd build_x86 7.msbuild Range-v3.sln /p:Configuration=Release /p:Platform=win32 /m /t:Rebuild

log_x86_build.log

Actual result: D:\Range-v3\src\test\algorithm./set_symmetric_difference.hpp(46,5): error C2672: 'operator surrogate_func': no matching overloaded function found D:\Range-v3\src\test\algorithm./set_symmetric_difference.hpp(46,1): error C2893: Failed to specialize function template 'checker test_range_algo_2<ranges::set_symmetric_difference_fn,false,false>::operator ()(I1,I1,I2,I2,Rest &&...) const' [D:\Range-v3\build_x86\test\algorithm\alg.set_symmetric_difference1.vcxproj] D:\Range-v3\src\test\algorithm\reverse_copy.cpp(42,1): error C2780: 'identity<enable_if<ranges::BidirectionalRange&&ranges::WeaklyIncrementable&&ranges::IndirectlyCopyable<unknown-type,O>||'function',void>::type>::invoke<ranges::detail::in_out_result<ifthen<ranges::ForwardingRange>::apply<unknown-type,ranges::dangling>,O>> ranges::reverse_copy_fn::operator ()(Rng &&,O) const': expects 2 arguments - 3 provided [D:\Range-v3\build_x86\test\algorithm\alg.reverse_copy.vcxproj] D:\Range-v3\src\test\algorithm\reverse_copy.cpp(43,1): error C2783: 'void check_equal_fn::operator ()(Rng &&,std::initializer_list &&) const': could not deduce template argument for 'formal' [D:\Range-v3\build_x86\test\algorithm\alg.reverse_copy.vcxproj]

ericniebler commented 5 years ago

It looks like you are not building with the flags that are (now) required. From the docs:

Visual Studio 2019 Preview 4 (or later) on Windows, with some caveats due to range-v3's strict conformance requirements: range-v3 needs /std:c++17 /permissive- range-v3 needs a fully conforming preprocessor, so /experimental:preprocesor is necessary. Note that the conforming preprocessor diagnoses C5105 "macro expansion producing 'defined' has undefined behavior" in some of the Windows SDK headers, so you'll probably want to suppress that warning with /wd5105.

spacelg commented 5 years ago

Thanks for your reply!

Our cl command as below:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\CL.exe /c /I"D:\Range-v3\src\include" /nologo /W3 /WX /diagnostics:caret /O2 /Ob2 /Oy- /D WIN32 /D _WINDOWS /D NDEBUG /D "CMAKE_INTDIR=\"Release\"" /D _MBCS /Gm- /EHsc /MD /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /std:c++17 /Fo"alg.search_n.dir\Release\" /Fd"alg.search_n.dir\Release\vc141.pdb" /Gd /TP /wd5105 /analyze- /errorReport:queue /permissive- /experimental:preprocessor /await "D:\Range-v3\src\test\algorithm\search_n.cpp"

These options are already included. We will report this to the MSVC team to confirm if this is a source issue.

Thanks Lin

TheQwertiest commented 5 years ago

@ericniebler hm, I've got a similar(?) error when compiling the header with VS2019 16.1 (non-Preview), which should be newer than the required VS2019 (16.0?) Preview 4

#include <range/v3/all.hpp>

with the following flags /permissive- /experimental:preprocessor /wd5105 /std:c++17:

range/v3/utility/random.hpp(105): error C2672: 'operator __surrogate_func': no matching overloaded function found
range/v3/utility/random.hpp(105): error C2783: 'identity<enable_if<ranges::Invocable<F&,>&&ranges::OutputRange<Rng,_invoke_result_<void,F&,>::type>||'function',void>::type>::invoke<ranges::detail::out_fun_result<if_then<ranges::ForwardingRange_<R>>::apply<unknown-type,ranges::dangling>,F>> ranges::generate_fn::operator ()(Rng &&,F) const': could not deduce template argument for 'O'
range/v3/algorithm/generate.hpp(48): note: see declaration of 'ranges::generate_fn::operator ()'
range/v3/algorithm/sample.hpp(145): warning C4996: 'ranges::difference_type_t': ranges::difference_type_t is deprecated. Please use ranges::iter_difference_t instead.
range/v3/iterator/traits.hpp(159): note: see declaration of 'ranges::difference_type_t'

Am I missing something?

melston commented 5 years ago

I'm seeing something very similar. I have a simple console application. I have the following includes

#include <iostream>
#include <string>
#include <range/v3/all.hpp>

After this is a simple class decfinition and the main function that doesn't do anything yet. This gives the following:

...\include\range\v3\utility\random.hpp(105): error C2672: 'operator __surrogate_func': no matching overloaded function found
...\include\range\v3\utility\random.hpp(105): error C2893: Failed to specialize function template 'identity<enable_if<ranges::Invocable<F&,>&&ranges::OutputRange<Rng,_invoke_result_<void,F&,>::type>||'function',void>::type>::invoke<ranges::detail::out_fun_result<if_then<ranges::ForwardingRange_<R>>::apply<unknown-type,ranges::dangling>,F>> ranges::generate_fn::operator ()(Rng &&,F) const'
...\include\range\v3\utility\random.hpp(105): note: With the following template arguments:
...\include\range\v3\utility\random.hpp(105): note: 'Rng=std::array<uint32_t,8> &'
...\include\range\v3\utility\random.hpp(105): note: 'F=ranges::detail::randutils::get_entropy::<lambda_ad7450e0be53cbd052bdd96f557a4911>'
...\include\range\v3\algorithm\sample.hpp(145): error C4996: 'ranges::difference_type_t': ranges::difference_type_t is deprecated. Please use ranges::iter_difference_t instead.
...\include\range\v3\iterator\traits.hpp(159): note: see declaration of 'ranges::difference_type_t'

VS 2019 Community, 16.0.4

In addition there are 1401 errors in the Error List tab from the standard includes (like random) plus errors from the range headers (like concepts.hpp, adjacent_remove_if.hpp, and others). Something has really confused the compiler (or pre-processor) here.

melston commented 5 years ago

One more detail to be mentioned. I was testing this with the github version I cloned. I ran cmake with the Visual Studio 2019 generator option and included the provided include directory and got the errors listed above.

I just built and used vpkg to install ranges-v3 and now it works as expected.

If there are some specific steps to be used to make the github project work in VS 2019 please add them to the Readme.

MignonBelongie commented 5 years ago

On a related note, /experimental:preprocessor is misspelled as /experimental:preprocesor in README.md.

lc47 commented 5 years ago

Would the /Zc:__cplusplus switch be recommended here also?

CaseyCarter commented 5 years ago

Updating the thread:

@spacelg range-v3's master branch no longer supports VS2017. VS2017 users should stick to 0.5.0 (which is currently the version installed by vcpkg.)

@TheQwertiest and @melston VS2019 support has fallen behind tip-of-trunk, #1221 should catch us back up again.

@MignonBelongie README fixed also in #1221 - good catch.

@lc47 range-v3 uses _MSVC_LANG to detect the language version when it's greater than __cplusplus, so it doesn't care at all about /Zc:__cplusplus.