C2143 / C2518 when trying to compile a project using boost.multiprecision

I had problems trying to get boost.multiprecision to work in my VC2017 project, and I tried to make the simplest project possible as a proof of concept:

#include<boost/multiprecision/cpp_int.hpp> int main() { boost::multiprecision::cpp_int val{ 5 }; val *= 5; val *= 5; return val.convert_to<int>(); } 

Unfortunately, this code does not compile with the following errors:

 1>------ Build started: Project: Multiprecision Test, Configuration: Debug x64 ------ 1>Multi Main.cpp 1>Unknown compiler version - please run the configure tests and report the results 1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(36): error C2143: syntax error: missing ',' before '<' 1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(40): note: see reference to class template instantiation 'boost::equal_pointees_t<OptionalPointee>' being compiled 1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(59): error C2143: syntax error: missing ',' before '<' 1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(63): note: see reference to class template instantiation 'boost::less_pointees_t<OptionalPointee>' being compiled 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(453): error C2143: syntax error: missing ',' before '<' 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(467): note: see reference to class template instantiation 'boost::numeric::convdetail::trivial_converter_impl<Traits>' being compiled 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(453): error C2518: keyword 'typename' illegal in base class list; ignored 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(454): error C2518: keyword 'typename' illegal in base class list; ignored 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(474): error C2143: syntax error: missing ',' before '<' 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(497): note: see reference to class template instantiation 'boost::numeric::convdetail::rounding_converter<Traits,RangeChecker,RawConverter,Float2IntRounder>' being compiled 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(474): error C2518: keyword 'typename' illegal in base class list; ignored 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(475): error C2518: keyword 'typename' illegal in base class list; ignored 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(504): error C2143: syntax error: missing ',' before '<' 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(526): note: see reference to class template instantiation 'boost::numeric::convdetail::non_rounding_converter<Traits,RangeChecker,RawConverter>' being compiled 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(504): error C2518: keyword 'typename' illegal in base class list; ignored 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(505): error C2518: keyword 'typename' illegal in base class list; ignored 1>Done building project "Multiprecision Test.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ========== 

These are the same errors that I get in a more complex project that originally used boost.multiprecision. I had no problems compiling this code in Visual Studio 2015. Does anyone know what happened and what do I need to do to fix this?

EDIT:

A project using boost.asio compiles without problems:

 #include<boost/asio.hpp> #include<iostream> int main() { boost::asio::io_service service; for (int i = 0; i < 10; i++) { service.post([i] { std::cout << i << std::endl; }); } service.run(); system("pause"); return 0; } 
+6
source share
1 answer

The problem is that some templates in boost::multiprecision use std::unary_function , which is deprecated since C ++ 11 and has been removed from the standard for C ++ 17.

Defenders such as #if _HAS_AUTO_PTR_ETC around such deprecated definitions were introduced into the standard library implementation in MSVC 2015. They are set to 1 by default with the new switch /std:c++14 (by default) and by default set to 0 in the /std:c++latest section (new compiler keys are available starting with 2015 Update 3).

So, until boost removes the dependency on std::unary_function , you should either not use /std:c++latest (I always used it from the moment it was released), or #define _HAS_AUTO_PTR_ETC 1 before turning on ( directly or indirectly) any standard library headers. Thus, either install it with the compiler options, or in some PCH, which is the first to be included in all translation units or something like that.

A detailed description of these settings, including other security guards who control other obsolete or remote functions, can be found in this blog post from Stephan T. Lawave. Visual C ++ 2003 - 2015 Change History is apparently the official list of changes in MSVC, but unfortunately it does not cover all these details. In general, scanning Visual C ++ Team Blog for posts from Stephan will give you the best information about these things.

+14
source

Source: https://habr.com/ru/post/1014611/


All Articles