boostorg / boostorg/safe_numerics
Avoid spurious warnings when gcc's -Wconversion is used
- Dominant language
- C++
- Stars
- 222
- Forks
- 46
- PR merge metrics
- No merged PRs in 30d
Description
Consider:
#include
#include
using I = boost::safe_numerics::safe;
struct X { I i; };
std::optional f(X x)
{
return x.i;
}
When asked to compile the above with `-Wconversion`, `g++` gives:
t.cpp: In function ‘std::optional > > f(X)’:
t.cpp:10:14: warning: choosing ‘constexpr std::optional<_Tp>::optional(_Up&&) [with _Up = boost::safe_numerics::safe_base >&; typename std::enable_if, typename std::decay<_Up>::type> >, std::__not_::type> >, std::is_constructible<_Tp, _Up&&>, std::is_convertible<_Up&&, _Tp> >::value, bool>::type = 1; _Tp = boost::safe_numerics::safe_base >]’ over ‘constexpr boost::safe_numerics::safe_base::operator R() const [with R = std::optional > >; typename std::enable_if<(! boost::safe_numerics::is_safe::value), int>::type = 0; Stored = int; Stored Min = -2147483648; Stored Max = 2147483647; P = boost::safe_numerics::native; E = boost::safe_numerics::exception_policy]’ [-Wconversion]
return x.i;
^
t.cpp:10:14: warning: for conversion from ‘I’ {aka ‘boost::safe_numerics::safe_base >’} to ‘std::optional > >’ [-Wconversion]
t.cpp:10:14: note: because conversion sequence for the argument is better
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.