diff --git a/include/cpp2util.h b/include/cpp2util.h index 57ed3c651..06206def2 100644 --- a/include/cpp2util.h +++ b/include/cpp2util.h @@ -1224,14 +1224,14 @@ constexpr auto assert_not_zero(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAUL if constexpr (std::is_signed_v) { return std::ssize(x); } \ else { return std::size(x); } \ }; \ - auto msg = "out of bounds access attempt detected - attempted access at index " + std::to_string(arg) + ", "; \ - if (max() > 0 ) { \ - msg += "[min,max] range is [0," + std::to_string(max()-1) + "]"; \ - } \ - else { \ - msg += "but container is empty"; \ - } \ if (!(0 <= arg && arg < max())) { \ + auto msg = "out of bounds access attempt detected - attempted access at index " + std::to_string(arg) + ", "; \ + if (max() > 0 ) { \ + msg += "[min,max] range is [0," + std::to_string(max()-1) + "]"; \ + } \ + else { \ + msg += "but container is empty"; \ + } \ bounds_safety.report_violation(msg.c_str() CPP2_SOURCE_LOCATION_ARG); \ } \ return CPP2_FORWARD(x) [ arg ]; \