From 29d0cfec7cdc14481a9cced4bcf7dc661398af55 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 14 Apr 2026 12:38:59 +0200 Subject: [PATCH] Suppress false positive compiler warnings when compiling with -O3 (#1389) * Print test names at test time (#1343) * Suppress false positive compiler warnings when compiling with -O3 The CI checks currently only check everything with -O0. Wenn activating higher optimization levels, more warnings kick in. Leading to errors, depending on the configuration. --------- Co-authored-by: John Wellbelove Co-authored-by: John Wellbelove --- include/etl/algorithm.h | 18 ++++++++++++++++++ include/etl/priority_queue.h | 2 ++ test/test_algorithm.cpp | 4 ++++ test/test_forward_list.cpp | 2 ++ test/test_forward_list_shared_pool.cpp | 2 ++ test/test_intrusive_forward_list.cpp | 2 ++ test/test_intrusive_list.cpp | 2 ++ test/test_multiset.cpp | 6 ++---- test/test_ranges.cpp | 2 ++ test/test_set.cpp | 4 ++-- 10 files changed, 38 insertions(+), 6 deletions(-) diff --git a/include/etl/algorithm.h b/include/etl/algorithm.h index 63bfe13b..162deaf9 100644 --- a/include/etl/algorithm.h +++ b/include/etl/algorithm.h @@ -898,6 +898,7 @@ namespace etl { TDistance parent = (value_index - 1) / 2; +#include "etl/private/diagnostic_array_bounds_push.h" while ((value_index > top_index) && compare(first[parent], value)) { first[value_index] = ETL_MOVE(first[parent]); @@ -906,6 +907,7 @@ namespace etl } first[value_index] = ETL_MOVE(value); +#include "etl/private/diagnostic_pop.h" } // Adjust Heap Helper @@ -1358,7 +1360,9 @@ namespace etl value_type temp(ETL_MOVE(*first)); // Move the rest. +#include "etl/private/diagnostic_stringop_overread_push.h" TIterator result = etl::move(etl::next(first), last, first); +#include "etl/private/diagnostic_pop.h" // Restore the first item in its rotated position. *result = ETL_MOVE(temp); @@ -2786,7 +2790,9 @@ namespace etl d_size_type d_size = etl::distance(o_begin, o_end); min_size_type min_size = etl::min(s_size, d_size); + #include "etl/private/diagnostic_null_dereference_push.h" return etl::move(i_begin, i_begin + min_size, o_begin); + #include "etl/private/diagnostic_pop.h" } //*************************************************************************** @@ -5860,12 +5866,14 @@ namespace etl } } + #include "etl/private/diagnostic_array_bounds_push.h" // Sort the heap to produce a sorted output range for (auto heap_end = heap_size - 1; heap_end > 0; --heap_end) { etl::iter_swap(result_first, result_first + heap_end); sift_down(result_first, decltype(heap_size){0}, heap_end, comp, proj2); } + #include "etl/private/diagnostic_pop.h" return {etl::move(in_last), etl::move(r)}; } @@ -6202,6 +6210,16 @@ namespace etl I left_partition = stable_partition_impl(first, middle, etl::ref(pred), etl::ref(proj), len / 2); I right_partition = stable_partition_impl(middle, last, etl::ref(pred), etl::ref(proj), len - len / 2); + if (left_partition == middle) + { + return right_partition; + } + + if (middle == right_partition) + { + return left_partition; + } + return etl::rotate(left_partition, middle, right_partition); } }; diff --git a/include/etl/priority_queue.h b/include/etl/priority_queue.h index e72d4908..2623fc07 100644 --- a/include/etl/priority_queue.h +++ b/include/etl/priority_queue.h @@ -439,7 +439,9 @@ namespace etl //************************************************************************* void clone(const ipriority_queue& other) { +#include "etl/private/diagnostic_uninitialized_push.h" assign(other.container.cbegin(), other.container.cend()); +#include "etl/private/diagnostic_pop.h" } #if ETL_USING_CPP11 diff --git a/test/test_algorithm.cpp b/test/test_algorithm.cpp index fa0f4f0e..abc5f734 100644 --- a/test/test_algorithm.cpp +++ b/test/test_algorithm.cpp @@ -2621,8 +2621,10 @@ namespace for (size_t i = 0UL; i <= initial_data.size(); ++i) { +#include "etl/private/diagnostic_null_dereference_push.h" std::vector data1(initial_data); std::vector data2(initial_data); +#include "etl/private/diagnostic_pop.h" auto std_result = std::rotate(data1.data(), data1.data() + i, data1.data() + data1.size()); auto etl_result = etl::rotate(data2.data(), data2.data() + i, data2.data() + data2.size()); @@ -2658,8 +2660,10 @@ namespace for (size_t i = 0UL; i <= initial_data.size(); ++i) { +#include "etl/private/diagnostic_null_dereference_push.h" std::vector data1(initial_data); std::vector data2(initial_data); +#include "etl/private/diagnostic_pop.h" auto std_result = std::rotate(data1.data(), data1.data() + i, data1.data() + data1.size()); diff --git a/test/test_forward_list.cpp b/test/test_forward_list.cpp index 08337c28..02d928de 100644 --- a/test/test_forward_list.cpp +++ b/test/test_forward_list.cpp @@ -42,6 +42,7 @@ SOFTWARE. namespace { +#include "etl/private/diagnostic_null_dereference_push.h" SUITE(test_forward_list) { const size_t SIZE = 10UL; @@ -1444,4 +1445,5 @@ namespace } #endif } +#include "etl/private/diagnostic_pop.h" } // namespace diff --git a/test/test_forward_list_shared_pool.cpp b/test/test_forward_list_shared_pool.cpp index 701bfe44..996efe7a 100644 --- a/test/test_forward_list_shared_pool.cpp +++ b/test/test_forward_list_shared_pool.cpp @@ -42,6 +42,7 @@ SOFTWARE. namespace { +#include "etl/private/diagnostic_null_dereference_push.h" SUITE(test_forward_list) { const size_t SIZE = 20UL; @@ -1929,4 +1930,5 @@ namespace CHECK(data3 > data1); } } +#include "etl/private/diagnostic_pop.h" } // namespace diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index 33002fd7..5be470bc 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -129,6 +129,7 @@ namespace namespace { +#include "etl/private/diagnostic_null_dereference_push.h" SUITE(test_intrusive_forward_list) { InitialDataNDC stable_sort_data; @@ -1379,4 +1380,5 @@ namespace CHECK_FALSE(data0.contains(compare_node2)); } } +#include "etl/private/diagnostic_pop.h" } // namespace diff --git a/test/test_intrusive_list.cpp b/test/test_intrusive_list.cpp index 0c352b5d..4b2f6f85 100644 --- a/test/test_intrusive_list.cpp +++ b/test/test_intrusive_list.cpp @@ -142,6 +142,7 @@ namespace namespace { +#include "etl/private/diagnostic_null_dereference_push.h" SUITE(test_intrusive_list) { InitialDataNDC stable_sort_data; @@ -1648,4 +1649,5 @@ namespace CHECK_FALSE(data0.contains(compare_node2)); } } +#include "etl/private/diagnostic_pop.h" } // namespace diff --git a/test/test_multiset.cpp b/test/test_multiset.cpp index c040e8ac..6cf29f87 100644 --- a/test/test_multiset.cpp +++ b/test/test_multiset.cpp @@ -98,10 +98,10 @@ namespace return (lhs < rhs.k); } +#include "etl/private/diagnostic_null_dereference_push.h" SUITE(test_multiset) { //************************************************************************* -#include "etl/private/diagnostic_null_dereference_push.h" template bool Check_Equal(T1 begin1, T1 end1, T2 begin2) { @@ -118,7 +118,6 @@ namespace return true; } -#include "etl/private/diagnostic_pop.h" //************************************************************************* struct SetupFixture @@ -1515,7 +1514,6 @@ namespace for (pos = data.crbegin(); pos != data.crend(); ++pos) { -#include "etl/private/diagnostic_null_dereference_push.h" if (*pos > prv) { pass = false; @@ -1523,7 +1521,6 @@ namespace } prv = *pos; -#include "etl/private/diagnostic_pop.h" } CHECK(pass); @@ -1630,4 +1627,5 @@ namespace } while (std::next_permutation(permutation.begin(), permutation.end())); } } +#include "etl/private/diagnostic_pop.h" } // namespace diff --git a/test/test_ranges.cpp b/test/test_ranges.cpp index 0fe4c41b..01b20c95 100644 --- a/test/test_ranges.cpp +++ b/test/test_ranges.cpp @@ -157,6 +157,7 @@ namespace std namespace { + #include "etl/private/diagnostic_null_dereference_push.h" SUITE(test_ranges) { //************************************************************************* @@ -5740,6 +5741,7 @@ namespace CHECK_EQUAL(30, v_out[2]); } } + #include "etl/private/diagnostic_pop.h" } // namespace #endif diff --git a/test/test_set.cpp b/test/test_set.cpp index f8f56d50..0fe643bf 100644 --- a/test/test_set.cpp +++ b/test/test_set.cpp @@ -103,10 +103,10 @@ namespace // return (lhs.k < rhs.k); // } +#include "etl/private/diagnostic_null_dereference_push.h" SUITE(test_set) { //************************************************************************* -#include "etl/private/diagnostic_null_dereference_push.h" template bool Check_Equal(T1 begin1, T1 end1, T2 begin2) { @@ -123,7 +123,6 @@ namespace return true; } -#include "etl/private/diagnostic_pop.h" //************************************************************************* struct SetupFixture @@ -1443,4 +1442,5 @@ namespace } while (std::next_permutation(permutation.begin(), permutation.end())); } } +#include "etl/private/diagnostic_pop.h" } // namespace