From d5156f9a1a55574dd585f4820c870beb5c8a1773 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Mon, 7 Sep 2026 14:42:44 +0200 Subject: [PATCH] Fix false positive warning from GCC 16 (#1591) --- include/etl/const_map.h | 5 +++++ include/etl/const_multimap.h | 5 +++++ include/etl/const_multiset.h | 5 +++++ include/etl/const_set.h | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/include/etl/const_map.h b/include/etl/const_map.h index 6bcab37d..f0c50be2 100644 --- a/include/etl/const_map.h +++ b/include/etl/const_map.h @@ -505,6 +505,7 @@ namespace etl static_assert((etl::is_default_constructible::value), "key_type must be default constructible"); static_assert((etl::is_default_constructible::value), "mapped_type must be default constructible"); + #include "private/diagnostic_uninitialized_push.h" //************************************************************************* ///\brief Construct a const_map from a variadic list of elements. /// Static asserts if the elements are not constructible into @@ -512,6 +513,9 @@ namespace etl /// Static asserts if the number of elements is greater than the capacity of /// the const_map. //************************************************************************* + // The base class is passed the address of 'element_list' before that member has been + // initialised. The base class only stores the address and never reads through it during + // construction, so the compiler's 'may be used uninitialized' warning is a false positive. template ETL_CONSTEXPR14 explicit const_map(TElements&&... elements) ETL_NOEXCEPT : iconst_map(element_list, sizeof...(elements), Size) @@ -521,6 +525,7 @@ namespace etl "All elements must be constructible into value_type"); static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity"); } + #include "private/diagnostic_pop.h" private: diff --git a/include/etl/const_multimap.h b/include/etl/const_multimap.h index 824abf77..1ec056a3 100644 --- a/include/etl/const_multimap.h +++ b/include/etl/const_multimap.h @@ -454,6 +454,7 @@ namespace etl static_assert((etl::is_default_constructible::value), "key_type must be default constructible"); static_assert((etl::is_default_constructible::value), "mapped_type must be default constructible"); + #include "private/diagnostic_uninitialized_push.h" //************************************************************************* ///\brief Construct a const_map from a variadic list of elements. /// Static asserts if the element type is not constructible. @@ -462,6 +463,9 @@ namespace etl /// Static asserts if the number of elements is greater than the capacity of /// the const_map. //************************************************************************* + // The base class is passed the address of 'element_list' before that member has been + // initialised. The base class only stores the address and never reads through it during + // construction, so the compiler's 'may be used uninitialized' warning is a false positive. template ETL_CONSTEXPR14 explicit const_multimap(TElements&&... elements) ETL_NOEXCEPT : iconst_multimap(element_list, sizeof...(elements), Size) @@ -471,6 +475,7 @@ namespace etl "All elements must be constructible into value_type"); static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity"); } + #include "private/diagnostic_pop.h" private: diff --git a/include/etl/const_multiset.h b/include/etl/const_multiset.h index 28e9567d..f0bb70fb 100644 --- a/include/etl/const_multiset.h +++ b/include/etl/const_multiset.h @@ -409,6 +409,7 @@ namespace etl static_assert((etl::is_default_constructible::value), "key_type must be default constructible"); + #include "private/diagnostic_uninitialized_push.h" //************************************************************************* ///\brief Construct a const_set from a variadic list of elements. /// Static asserts if the element type is not constructible. @@ -416,6 +417,9 @@ namespace etl /// Static asserts if the number of elements is greater than the capacity of /// the const_set. //************************************************************************* + // The base class is passed the address of 'element_list' before that member has been + // initialised. The base class only stores the address and never reads through it during + // construction, so the compiler's 'may be used uninitialized' warning is a false positive. template ETL_CONSTEXPR14 explicit const_multiset(TElements&&... elements) ETL_NOEXCEPT : iconst_multiset(element_list, sizeof...(elements), Size) @@ -424,6 +428,7 @@ namespace etl static_assert((etl::are_all_same...>::value), "All elements must be value_type"); static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity"); } + #include "private/diagnostic_pop.h" private: diff --git a/include/etl/const_set.h b/include/etl/const_set.h index 29841dba..92bbad2c 100644 --- a/include/etl/const_set.h +++ b/include/etl/const_set.h @@ -403,12 +403,16 @@ namespace etl static_assert((etl::is_default_constructible::value), "key_type must be default constructible"); + #include "private/diagnostic_uninitialized_push.h" //************************************************************************* ///\brief Construct a const_set from a variadic list of elements. /// Static asserts if the elements are not of type value_type. /// Static asserts if the number of elements is greater than the capacity of /// the const_set. //************************************************************************* + // The base class is passed the address of 'element_list' before that member has been + // initialised. The base class only stores the address and never reads through it during + // construction, so the compiler's 'may be used uninitialized' warning is a false positive. template ETL_CONSTEXPR14 explicit const_set(TElements&&... elements) ETL_NOEXCEPT : iconst_set(element_list, sizeof...(elements), Size) @@ -417,6 +421,7 @@ namespace etl static_assert((etl::are_all_same...>::value), "All elements must be key_type"); static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity"); } + #include "private/diagnostic_pop.h" private: