Open Eelis opened 3 years ago
I'm not sure that this has anything to do with safe_numerics per se but rather using implicit conversion of member variable to wrapper type. I'll leave this here while I think about it some more. Here is the page describing the warning for this particular case: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html . I'm thinking that gcc is being overly picky here. See "For C++, also warn for confusing overload resolution for user-defined conversions; and conversions that never use a type conversion operator". Also checkout what other compilers do in this case.
For now I think the prudent thing to do is to replace the implicit conversion with a more explicit one.
#include <optional>
#include <boost/safe_numerics/safe_integer.hpp>
using I = boost::safe_numerics::safe<int>;
struct X { I i; };
std::optional<I> f(X x)
{
return std::optional<I>(x.i);
}
I'm not sure that this has anything to do with safe_numerics per se but rather using implicit conversion of member variable to wrapper type.
If I use using I = int;
or struct I{};
instead, the warning goes away. That made me think the issue had something to do with safe_numerics, but if that's not the case, feel free to close. :)
Consider:
When asked to compile the above with
-Wconversion
,g++
gives: