Skip to content

Commit

Permalink
Disable spurious gcc warning in xfunction::broadcast_shape
Browse files Browse the repository at this point in the history
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<size_t, 1>`.

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107852
  • Loading branch information
hsanzg committed Nov 19, 2024
1 parent 8c0a484 commit 7860ec6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/xtensor/xfunction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ namespace xt

tuple_type m_e;
functor_type m_f;
mutable xfunction_cache<detail::promote_index<typename std::decay_t<CT>::shape_type...>> m_cache;
mutable xfunction_cache<detail::promote_index<typename std::decay_t<CT>::shape_type...>> m_cache{};

friend class xfunction_iterator<F, CT...>;
friend class xfunction_stepper<F, CT...>;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7860ec6

Please sign in to comment.