Latest Results
Avoid GCC -Warray-bounds false positive on fixed-size shape copies (#2946)
# Description
GCC 13 and 15 emit `-Warray-bounds` at `-O2`/`-O3` on ordinary code
using fixed-rank containers, for example assigning `0.5 * (even + odd)`
to a 1-D `xtensor` view. The warning comes from a `std::copy` between
two `std::array<std::size_t, 1>` when the source is a member at a
non-zero offset. GCC does not fold the length of the range and warns on
the `memmove` branch that libstdc++ keeps for ranges of more than one
element. That branch never runs. Reproducer without xtensor:
```cpp
struct holder { std::size_t m_size; std::array<std::size_t, 1> m_shape; };
std::array<std::size_t, 1> f(const holder& h)
{
std::array<std::size_t, 1> s;
std::copy(h.m_shape.cbegin(), h.m_shape.cend(), s.begin());
return s;
}
```
These copies now use `std::copy_n(src.begin(), src.size(),
dst.begin())`. `size()` is a constant for `std::array`, so GCC drops the
branch. At each site the destination is sized from the same source, so
the copied elements do not change. Changed sites:
`xfunction::broadcast_shape`, the `xbroadcast` constructor, `flip`
(shape and strides), and `average` with multi-dimensional weights.
`std::copy(data(), data() + size())` and `std::ranges::copy` still warn.
No unit test, since this is a compile-time warning and CI does not build
with `-Wall` on GCC. A file using 1-D, 2-D and 3-D views, reductions,
broadcasting, `flip` and `xtensor_fixed` now compiles without warnings
with GCC 13.4 and 15.3 at `-O2` and `-O3` with `-Wall -Wextra`, with and
without xsimd. Latest Branches
0%
0%
0%
gouarin:fix-xview-element-newaxis © 2026 CodSpeed Technology