Latest Results
Fix -Wshadow and remaining -Wall -Wextra warnings (#2956)
# Checklist
- [x] The title and commit message(s) are descriptive.
- [x] Small commits made to fix your PR have been squashed to avoid
history pollution.
- [x] Tests have been added for new features or bug fixes.
- [x] API of new functions and classes are documented (no public API
changes).
# Description
This PR fixes the `-Wshadow` warnings and the remaining `-Wall -Wextra
-Wpedantic` warnings that are not conversion or flow-sensitive ones
(`-Wimplicit-fallthrough`, `-Wparentheses`, unused typedefs and
parameters, `-Wextra-semi`, `-Wmismatched-tags`,
`-Wbitwise-instead-of-logical`, `-Wpessimizing-move`,
`-Wabsolute-value`, `-Wbraced-scalar-init`). Parameters and locals that
shadow something get a clearer name. Nothing is silenced with pragmas.
Warning sites in scope:
| | GCC 13 | GCC 15 | clang 20 |
|---|---|---|---|
| master | 54 | 51 | 34 |
| this PR + #2954 + #2955 | 0 | 0 | 0 |
The count is also 0 with `XTENSOR_USE_XSIMD` (GCC 15) and
`XTENSOR_ENABLE_ASSERT` (GCC 13, clang 20).
Two warnings pointed at library bugs, fixed separately: the `argsort`
fallthrough (#2954) and `xoptional_assembly_storage::data()` (#2955).
Two more were test bugs, fixed here:
- in `test_xreducer`, the type-check macros shadowed the expected type,
so `CHECK_RESULT_TYPE` compared a type with itself and could never fail;
- `math::abs(char(1))` does not test a signed type where `char` is
unsigned (aarch64); it now uses `signed char` with -1.
Unused test aliases became assertions where they named something worth
checking. 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