boostorg / boostorg/safe_numerics
"error: no match for call to" in exception_policies.hpp
- Dominant language
- C++
- Stars
- 222
- Forks
- 46
- PR merge metrics
- No merged PRs in 30d
Description
While working on a sample for #129 I tried the following code ([godbolt.org](https://godbolt.org/z/qaW55EKj1)):
```c++
using delta_safe_t = boost::safe_numerics::safe_signed_range<
-1,
1,
boost::safe_numerics::native,
boost::safe_numerics::loose_trap_policy
>;
template
using const_safe_t = boost::safe_numerics::safe_signed_literal<
I,
boost::safe_numerics::native,
boost::safe_numerics::loose_trap_policy
>;
int main() {
constexpr auto x = const_safe_t<8>{};
std::cout << "x = " << safe_format(x) << '\n';
constexpr auto y = delta_safe_t{1};
std::cout << "y = " << safe_format(y) << '\n';
constexpr auto z = y * x;
std::cout << "z = " << safe_format(z) << '\n';
}
```
but it keeps failing with a lengthy error:
```plain
In file included from /opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_base.hpp:17,
from /opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_integer.hpp:15,
from /opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_integer_range.hpp:13,
from :3:
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/exception_policies.hpp: In instantiation of 'static constexpr void boost::safe_numerics::exception_policy::on_arithmetic_error(const boost::safe_numerics::safe_numerics_error&, const char*) [with AE = boost::safe_numerics::trap_exception; IDB = boost::safe_numerics::ignore_exception; UB = boost::safe_numerics::ignore_exception; UV = boost::safe_numerics::ignore_exception]':
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_base_operations.hpp:60:36: required from 'static constexpr boost::safe_numerics::checked_result boost::safe_numerics::heterogeneous_checked_operation::value && std::is_integral::value)>::type>::cast_impl_detail::cast_impl(const T&, std::true_type, std::true_type) [with R = signed char; R Min = -1; R Max = 1; T = int; F = boost::safe_numerics::dispatch_and_return, signed char>; std::true_type = std::integral_constant]'
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/checked_integer.hpp:148:40: required from here
:71:36: in 'constexpr' expansion of 'boost::safe_numerics::safe_base >(1)'
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_base_operations.hpp:195:23: in 'constexpr' expansion of '((boost::safe_numerics::safe_base >*)this)->boost::safe_numerics::safe_base >::validated_cast((* & t))'
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_base_operations.hpp:154:59: in 'constexpr' expansion of 'boost::safe_numerics::validate_detail >::return_value((* & t))'
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_base_operations.hpp:146:30: in 'constexpr' expansion of 'boost::safe_numerics::validate_detail >::exception_possible::return_value((* & t))'
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_base_operations.hpp:116:20: in 'constexpr' expansion of 'boost::safe_numerics::heterogeneous_checked_operation, signed char>, void>::cast((* & t))'
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/checked_integer.hpp:68:81: in 'constexpr' expansion of 'boost::safe_numerics::dispatch_and_return, signed char>::invoke(((const char*)"converted signed value too large"))'
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_base_operations.hpp:92:24: in 'constexpr' expansion of 'boost::safe_numerics::dispatch, boost::safe_numerics::safe_numerics_error::positive_overflow_error>(((const char*)msg))'
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_base_operations.hpp:82:50: in 'constexpr' expansion of 'boost::safe_numerics::dispatch_switch::dispatch_case, boost::safe_numerics::safe_numerics_actions::arithmetic_error>::invoke(boost::safe_numerics::safe_numerics_error::positive_overflow_error, msg)'
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/exception_policies.hpp:28:13: error: no match for call to '(boost::safe_numerics::trap_exception) (const boost::safe_numerics::safe_numerics_error&, const char*&)'
28 | AE()(e, msg);
| ~~~~^~~~~~~~
ASM generation compiler returned: 1
In file included from /opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_base.hpp:17,
from /opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_integer.hpp:15,
from /opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_integer_range.hpp:13,
from :3:
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/exception_policies.hpp: In instantiation of 'static constexpr void boost::safe_numerics::exception_policy::on_arithmetic_error(const boost::safe_numerics::safe_numerics_error&, const char*) [with AE = boost::safe_numerics::trap_exception; IDB = boost::safe_numerics::ignore_exception; UB = boost::safe_numerics::ignore_exception; UV = boost::safe_numerics::ignore_exception]':
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_base_operations.hpp:60:36: required from 'static constexpr boost::safe_numerics::checked_result boost::safe_numerics::heterogeneous_checked_operation::value && std::is_integral::value)>::type>::cast_impl_detail::cast_impl(const T&, std::true_type, std::true_type) [with R = signed char; R Min = -1; R Max = 1; T = int; F = boost::safe_numerics::dispatch_and_return, signed char>; std::true_type = std::integral_constant]'
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/checked_integer.hpp:148:40: required from here
:71:36: in 'constexpr' expansion of 'boost::safe_numerics::safe_base >(1)'
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_base_operations.hpp:195:23: in 'constexpr' expansion of '((boost::safe_numerics::safe_base >*)this)->boost::safe_numerics::safe_base >::validated_cast((* & t))'
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_base_operations.hpp:154:59: in 'constexpr' expansion of 'boost::safe_numerics::validate_detail >::return_value((* & t))'
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_base_operations.hpp:146:30: in 'constexpr' expansion of 'boost::safe_numerics::validate_detail >::exception_possible::return_value((* & t))'
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_base_operations.hpp:116:20: in 'constexpr' expansion of 'boost::safe_numerics::heterogeneous_checked_operation, signed char>, void>::cast((* & t))'
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/checked_integer.hpp:68:81: in 'constexpr' expansion of 'boost::safe_numerics::dispatch_and_return, signed char>::invoke(((const char*)"converted signed value too large"))'
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_base_operations.hpp:92:24: in 'constexpr' expansion of 'boost::safe_numerics::dispatch, boost::safe_numerics::safe_numerics_error::positive_overflow_error>(((const char*)msg))'
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/safe_base_operations.hpp:82:50: in 'constexpr' expansion of 'boost::safe_numerics::dispatch_switch::dispatch_case, boost::safe_numerics::safe_numerics_actions::arithmetic_error>::invoke(boost::safe_numerics::safe_numerics_error::positive_overflow_error, msg)'
/opt/compiler-explorer/libs/boost_1_80_0/boost/safe_numerics/exception_policies.hpp:28:13: error: no match for call to '(boost::safe_numerics::trap_exception) (const boost::safe_numerics::safe_numerics_error&, const char*&)'
28 | AE()(e, msg);
| ~~~~^~~~~~~~
```
What is wrong with my code?
Contributor guide
No contributing guide indexed for this repository
Research direction
Run the supplied C++ reproducer first, then inspect exception_policies.hpp and the safe_base_operations.hpp call path shown in the compiler trace. Determine why trap_exception cannot be called for this constexpr conversion; done means the reproducer builds successfully with the intended safe-numerics behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100