From 7860ec6af069468b27167a9a7791c70c957c971c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Sanz=20Gonz=C3=A1lez?= <80487270+hsanzg@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:27:24 +0100 Subject: [PATCH] Disable spurious gcc warning in `xfunction::broadcast_shape` Recent versions of gcc emit an incorrect `array-bounds` warning when copying the cached shape into the passed `input`, if the latter is of type `std::array`. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107852 --- include/xtensor/xfunction.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/xtensor/xfunction.hpp b/include/xtensor/xfunction.hpp index f11362cdb..3dd62865e 100644 --- a/include/xtensor/xfunction.hpp +++ b/include/xtensor/xfunction.hpp @@ -397,7 +397,7 @@ namespace xt tuple_type m_e; functor_type m_f; - mutable xfunction_cache::shape_type...>> m_cache; + mutable xfunction_cache::shape_type...>> m_cache{}; friend class xfunction_iterator; friend class xfunction_stepper; @@ -721,7 +721,13 @@ namespace xt { if (m_cache.is_initialized && reuse_cache) { + // Disable spurious warning when copying into a 1-sized `std::array` + // in gcc >= 12.4.0; see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107852 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Warray-bounds" + #pragma GCC diagnostic ignored "-Wstringop-overflow" std::copy(m_cache.shape.cbegin(), m_cache.shape.cend(), shape.begin()); + #pragma GCC diagnostic pop return m_cache.is_trivial; } else