From fbd738db691c41804cee60ffe87e5f94528c3fa3 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Wed, 22 Apr 2026 13:28:47 +0200 Subject: [PATCH] Replace deprecated builtin __is_trivially_relocatable if possible (#1402) Fixes: #1400 --- .../etl/profiles/determine_builtin_support.h | 43 ++++++++++++------- include/etl/type_traits.h | 11 ++++- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/include/etl/profiles/determine_builtin_support.h b/include/etl/profiles/determine_builtin_support.h index f2be5693..da15062a 100644 --- a/include/etl/profiles/determine_builtin_support.h +++ b/include/etl/profiles/determine_builtin_support.h @@ -159,6 +159,12 @@ SOFTWARE. #if !defined(ETL_USING_BUILTIN_IS_TRIVIALLY_RELOCATABLE) #define ETL_USING_BUILTIN_IS_TRIVIALLY_RELOCATABLE __has_builtin(__is_trivially_relocatable) #endif + + // __builtin_is_cpp_trivially_relocatable replaces __is_trivially_relocatable by an + // effort of standardization for newer C++ standards + #if !defined(ETL_USING_BUILTIN_BUILTIN_IS_CPP_TRIVIALLY_RELOCATABLE) + #define ETL_USING_BUILTIN_BUILTIN_IS_CPP_TRIVIALLY_RELOCATABLE __has_builtin(__builtin_is_cpp_trivially_relocatable) + #endif #endif // The default. Set to 0, if not already set. @@ -226,28 +232,33 @@ SOFTWARE. #define ETL_USING_BUILTIN_IS_TRIVIALLY_RELOCATABLE 0 #endif +#if !defined(ETL_USING_BUILTIN_BUILTIN_IS_CPP_TRIVIALLY_RELOCATABLE) + #define ETL_USING_BUILTIN_BUILTIN_IS_CPP_TRIVIALLY_RELOCATABLE 0 +#endif + namespace etl { namespace traits { // Documentation: https://www.etlcpp.com/etl_traits.html - static ETL_CONSTANT bool using_builtin_is_assignable = (ETL_USING_BUILTIN_IS_ASSIGNABLE == 1); - static ETL_CONSTANT bool using_builtin_is_constructible = (ETL_USING_BUILTIN_IS_CONSTRUCTIBLE == 1); - static ETL_CONSTANT bool using_builtin_is_nothrow_constructible = (ETL_USING_BUILTIN_IS_NOTHROW_CONSTRUCTIBLE == 1); - static ETL_CONSTANT bool using_builtin_is_nothrow_assignable = (ETL_USING_BUILTIN_IS_NOTHROW_ASSIGNABLE == 1); - static ETL_CONSTANT bool using_builtin_is_trivially_constructible = (ETL_USING_BUILTIN_IS_TRIVIALLY_CONSTRUCTIBLE == 1); - static ETL_CONSTANT bool using_builtin_is_trivially_destructible = (ETL_USING_BUILTIN_IS_TRIVIALLY_DESTRUCTIBLE == 1); - static ETL_CONSTANT bool using_builtin_is_trivially_copyable = (ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE == 1); - static ETL_CONSTANT bool using_builtin_underlying_type = (ETL_USING_BUILTIN_UNDERLYING_TYPE == 1); - static ETL_CONSTANT bool using_builtin_is_constant_evaluated = (ETL_USING_BUILTIN_IS_CONSTANT_EVALUATED == 1); - static ETL_CONSTANT bool using_builtin_memcpy = (ETL_USING_BUILTIN_MEMCPY == 1); - static ETL_CONSTANT bool using_builtin_memmove = (ETL_USING_BUILTIN_MEMMOVE == 1); - static ETL_CONSTANT bool using_builtin_memset = (ETL_USING_BUILTIN_MEMSET == 1); - static ETL_CONSTANT bool using_builtin_memcmp = (ETL_USING_BUILTIN_MEMCMP == 1); - static ETL_CONSTANT bool using_builtin_memchr = (ETL_USING_BUILTIN_MEMCHR == 1); - static ETL_CONSTANT bool using_builtin_is_virtual_base_of = (ETL_USING_BUILTIN_IS_VIRTUAL_BASE_OF == 1); - static ETL_CONSTANT bool using_builtin_is_trivially_relocatable = (ETL_USING_BUILTIN_IS_TRIVIALLY_RELOCATABLE == 1); + static ETL_CONSTANT bool using_builtin_is_assignable = (ETL_USING_BUILTIN_IS_ASSIGNABLE == 1); + static ETL_CONSTANT bool using_builtin_is_constructible = (ETL_USING_BUILTIN_IS_CONSTRUCTIBLE == 1); + static ETL_CONSTANT bool using_builtin_is_nothrow_constructible = (ETL_USING_BUILTIN_IS_NOTHROW_CONSTRUCTIBLE == 1); + static ETL_CONSTANT bool using_builtin_is_nothrow_assignable = (ETL_USING_BUILTIN_IS_NOTHROW_ASSIGNABLE == 1); + static ETL_CONSTANT bool using_builtin_is_trivially_constructible = (ETL_USING_BUILTIN_IS_TRIVIALLY_CONSTRUCTIBLE == 1); + static ETL_CONSTANT bool using_builtin_is_trivially_destructible = (ETL_USING_BUILTIN_IS_TRIVIALLY_DESTRUCTIBLE == 1); + static ETL_CONSTANT bool using_builtin_is_trivially_copyable = (ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE == 1); + static ETL_CONSTANT bool using_builtin_underlying_type = (ETL_USING_BUILTIN_UNDERLYING_TYPE == 1); + static ETL_CONSTANT bool using_builtin_is_constant_evaluated = (ETL_USING_BUILTIN_IS_CONSTANT_EVALUATED == 1); + static ETL_CONSTANT bool using_builtin_memcpy = (ETL_USING_BUILTIN_MEMCPY == 1); + static ETL_CONSTANT bool using_builtin_memmove = (ETL_USING_BUILTIN_MEMMOVE == 1); + static ETL_CONSTANT bool using_builtin_memset = (ETL_USING_BUILTIN_MEMSET == 1); + static ETL_CONSTANT bool using_builtin_memcmp = (ETL_USING_BUILTIN_MEMCMP == 1); + static ETL_CONSTANT bool using_builtin_memchr = (ETL_USING_BUILTIN_MEMCHR == 1); + static ETL_CONSTANT bool using_builtin_is_virtual_base_of = (ETL_USING_BUILTIN_IS_VIRTUAL_BASE_OF == 1); + static ETL_CONSTANT bool using_builtin_is_trivially_relocatable = (ETL_USING_BUILTIN_IS_TRIVIALLY_RELOCATABLE == 1); + static ETL_CONSTANT bool using_builtin_builtin_is_cpp_trivially_relocatable = (ETL_USING_BUILTIN_BUILTIN_IS_CPP_TRIVIALLY_RELOCATABLE == 1); } // namespace traits } // namespace etl diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 5732f935..2600da96 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -2728,6 +2728,9 @@ namespace etl #if ETL_HAS_STD_TRIVIALLY_RELOCATABLE && ETL_USING_STL template using is_trivially_relocatable = std::is_trivially_relocatable; + #elif ETL_USING_BUILTIN_BUILTIN_IS_CPP_TRIVIALLY_RELOCATABLE + template + using is_trivially_relocatable = etl::bool_constant<__builtin_is_cpp_trivially_relocatable(T)>; #elif ETL_USING_BUILTIN_IS_TRIVIALLY_RELOCATABLE template using is_trivially_relocatable = etl::bool_constant<__is_trivially_relocatable(T)>; @@ -2977,7 +2980,9 @@ namespace etl template struct is_trivially_relocatable { - #if ETL_USING_BUILTIN_IS_TRIVIALLY_RELOCATABLE + #if ETL_USING_BUILTIN_BUILTIN_IS_CPP_TRIVIALLY_RELOCATABLE + static ETL_CONSTANT bool value = __builtin_is_cpp_trivially_relocatable(T); + #elif ETL_USING_BUILTIN_IS_TRIVIALLY_RELOCATABLE static ETL_CONSTANT bool value = __is_trivially_relocatable(T); #else static ETL_CONSTANT bool value = etl::is_trivially_copyable::value && etl::is_trivially_destructible::value; @@ -3500,7 +3505,9 @@ namespace etl //********************************************* // is_trivially_relocatable template - #if ETL_USING_BUILTIN_IS_TRIVIALLY_RELOCATABLE + #if ETL_USING_BUILTIN_BUILTIN_IS_CPP_TRIVIALLY_RELOCATABLE + struct is_trivially_relocatable : public etl::bool_constant<__builtin_is_cpp_trivially_relocatable(T)> + #elif ETL_USING_BUILTIN_IS_TRIVIALLY_RELOCATABLE struct is_trivially_relocatable : public etl::bool_constant<__is_trivially_relocatable(T)> #else struct is_trivially_relocatable : public etl::bool_constant::value && etl::is_trivially_destructible::value>