From 7ac4016f552332d4f5f33a7ef6f4eb2e250ea962 Mon Sep 17 00:00:00 2001 From: Kp Date: Mon, 22 Aug 2022 01:24:49 +0000 Subject: [PATCH] Remove DXX_VALPTRIDX_STATIC_CHECK clang-14 is detected as being able to optimize out unreachable paths, but then triggers a build error reporting an unspecified invalid use somewhere in multi.cpp. Remove the static check, and rely on -Wsuggest-attribute=noreturn to report any functions which are guaranteed to fail. This is a weaker check, but over the course of development, the static check has been hit rarely, if ever, so keeping it provides little value. ``` In file included from similar/main/multi.cpp:38: In file included from common/main/game.h:32: In file included from common/main/robot.h:34: In file included from common/main/object.h:40: common/include/valptridx.h:229:2: error: call to unsigned int valptridx::check_index_range_size::index_range_exception, std::__1::less>(char const*, unsigned int, unsigned long, valptridx::array_managed_type const*)::DXX_ALWAYS_ERROR_FUNCTION::dxx_trap_handle_index_range_error() declared with 'error' attribute: invalid index used in array subscript DXX_VALPTRIDX_CHECK(Compare()(s, array_size), handle_index_range_error, "invalid index used in array subscript", a, s); ^ common/include/valptridx.h:37:3: note: expanded from macro 'DXX_VALPTRIDX_CHECK' DXX_VALPTRIDX_STATIC_CHECK(dxx_valptridx_check_success_condition, dxx_trap_##ERROR, FAILURE_STRING); \ ^ common/include/valptridx.h:20:5: note: expanded from macro 'DXX_VALPTRIDX_STATIC_CHECK' (DXX_ALWAYS_ERROR_FUNCTION(FAILURE_FUNCTION, FAILURE_STRING), 0) \ ^ build/ulinux-clang++-14-64b10d04-ogl/dxxsconf.h:84:2: note: expanded from macro 'DXX_ALWAYS_ERROR_FUNCTION' DXX_ALWAYS_ERROR_FUNCTION::F(); \ ^ 1 error generated. ``` --- common/include/valptridx.h | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/common/include/valptridx.h b/common/include/valptridx.h index 27f3fe0cd..ae037b42c 100644 --- a/common/include/valptridx.h +++ b/common/include/valptridx.h @@ -15,11 +15,6 @@ #include "selfiter.h" #ifdef DXX_CONSTANT_TRUE -#define DXX_VALPTRIDX_STATIC_CHECK(SUCCESS_CONDITION,FAILURE_FUNCTION,FAILURE_STRING) \ - static_cast(DXX_CONSTANT_TRUE(!SUCCESS_CONDITION) && \ - (DXX_ALWAYS_ERROR_FUNCTION(FAILURE_FUNCTION, FAILURE_STRING), 0) \ - ) \ - #ifdef DXX_HAVE_ATTRIBUTE_WARNING /* This causes many warnings because some conversions are not checked for * safety. Eliminating the warnings by changing the call sites to check first @@ -27,18 +22,12 @@ */ //#define DXX_VALPTRIDX_WARN_CALL_NOT_OPTIMIZED_OUT __attribute__((__warning__("call not eliminated"))) #endif -#else -#define DXX_VALPTRIDX_STATIC_CHECK(E,F,S) #endif -#define DXX_VALPTRIDX_CHECK(SUCCESS_CONDITION,ERROR,FAILURE_STRING,...) \ - ( DXX_BEGIN_COMPOUND_STATEMENT { \ - const bool dxx_valptridx_check_success_condition = (SUCCESS_CONDITION); \ - DXX_VALPTRIDX_STATIC_CHECK(dxx_valptridx_check_success_condition, dxx_trap_##ERROR, FAILURE_STRING); \ - static_cast( \ - dxx_valptridx_check_success_condition || (ERROR::report(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VA(__VA_ARGS__)), 0) \ - ); \ - } DXX_END_COMPOUND_STATEMENT ) +#define DXX_VALPTRIDX_CHECK(SUCCESS_CONDITION,ERROR,...) \ + static_cast( \ + static_cast(SUCCESS_CONDITION) || (ERROR::report(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VA(__VA_ARGS__)), 0) \ + ) \ #ifndef DXX_VALPTRIDX_WARN_CALL_NOT_OPTIMIZED_OUT #define DXX_VALPTRIDX_WARN_CALL_NOT_OPTIMIZED_OUT @@ -206,7 +195,7 @@ template void valptridx::check_index_match(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS const_reference_type r, index_type i, const array_managed_type &a __attribute_unused) { const auto pi = &a[i]; - DXX_VALPTRIDX_CHECK(pi == &r, handle_index_mismatch, "pointer/index mismatch", &a, i, pi, &r); + DXX_VALPTRIDX_CHECK(pi == &r, handle_index_mismatch, &a, i, pi, &r); } template @@ -226,7 +215,7 @@ template template class Compare> typename valptridx::index_type valptridx::check_index_range_size(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS const std::size_t s, const array_managed_type *const a) { - DXX_VALPTRIDX_CHECK(Compare()(s, array_size), handle_index_range_error, "invalid index used in array subscript", a, s); + DXX_VALPTRIDX_CHECK(Compare()(s, array_size), handle_index_range_error, a, s); /* This cast will truncate the value to fit in index_type, which is * normally smaller than std::size_t. However, truncation is legal * here, because (1) DXX_VALPTRIDX_CHECK would trap on an index that @@ -246,14 +235,14 @@ template template void valptridx::check_null_pointer_conversion(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS const_pointer_type p) { - DXX_VALPTRIDX_CHECK(p, handle_null_pointer, "NULL pointer converted"); + DXX_VALPTRIDX_CHECK(p, handle_null_pointer); } template template void valptridx::check_null_pointer(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS const_pointer_type p, const array_managed_type &a __attribute_unused) { - DXX_VALPTRIDX_CHECK(p, handle_null_pointer, "NULL pointer used", &a); + DXX_VALPTRIDX_CHECK(p, handle_null_pointer, &a); } template