Skip to content

Commit 2d9382d

Browse files
committed
Add attempted/actual bounds to default bounds checks messages
1 parent b41f60e commit 2d9382d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

include/cpp2util.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,11 @@ auto assert_in_bounds_impl(auto&& x, auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_
461461
requires (std::is_integral_v<CPP2_TYPEOF(arg)> &&
462462
requires { std::size(x); std::ssize(x); x[arg]; std::begin(x) + 2; })
463463
{
464-
Bounds.expects(0 <= arg && arg < [&]() -> auto {
464+
auto max = [&]() -> auto {
465465
if constexpr (std::is_signed_v<CPP2_TYPEOF(arg)>) { return std::ssize(x); }
466466
else { return std::size(x); }
467-
}(), "out of bounds access attempt detected" CPP2_SOURCE_LOCATION_ARG);
467+
};
468+
Bounds.expects(0 <= arg && arg < max(), ("out of bounds access attempt detected - attempted index " + std::to_string(arg) + ", [min,max] range is [0," + std::to_string(max()-1) + "]").c_str() CPP2_SOURCE_LOCATION_ARG);
468469
}
469470

470471
auto assert_in_bounds_impl(auto&&, auto&& CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> void

0 commit comments

Comments
 (0)