0

My project has been using boost 1.58 for ages. Now i have upgraded the visual studio version to 2017. And boost version 1.68.0

Boost 1.68.0 has some changes in its error_code class which breaks our build.

getting the following error

Error   C2440   '<function-style-cast>': cannot convert from 'cmdline_error' to 'boost::system::system_error'

where cmdline_error is defined as follows

enum cmdline_error
{
   success = 0,
   missing_argument,
   argument_conversion_failed
};

and this is the declaration which creates the error

cmdline_error cmdError;

boost::system::system_error systemError = boost::system::system_error(cmdError);

In linux build, the following error occurs

error: no matching function for call to ‘boost::system::system_error::system_error(cmdline_error)’

This code was working with boost 1.48, 1.58. 1.62

What is the correct way to handle this error here ?

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
  • `boost::system::system_error();` has constructor from `error_code`, but I do not see any constructor for `error_code` which would take a simple integral argument. – SergeyA Mar 04 '19 at 15:31
  • You can try `boost::system::system_error(boost::system::error_code(cmdError));` – Thomas Sablik Mar 04 '19 at 15:34
  • 6
    the `error_code` constructor of `system_error` has now been (correctly) marked as explicit to prevent accidental conversion of numbers to `system_error`. What is your code trying to achieve? If you want to use custom error numbers you really need to define a new error category – Alan Birtles Mar 04 '19 at 15:39
  • @ThomasSablik that wont work either, `boost::system::error_code` isn't constructible from enums unless `is_error_code_enum` is specialised to true – Alan Birtles Mar 04 '19 at 15:44
  • @ThomasSablik You mean extend error_category and write my own error category with numbers ? – Deepak Selvakumar Mar 04 '19 at 16:13
  • @ThomasSablik How to use the is_error_code_enum ? Is declaring some thing like template<> struct std::is_error_code_enum : public std::true_type{}; would work ? – Deepak Selvakumar Mar 04 '19 at 16:13
  • 1
    See the boost documentation for how to create your own error categories https://theboostcpplibraries.com/boost.system#ex.system_03 – Alan Birtles Mar 04 '19 at 16:22

0 Answers0