Skip to content

Fix -Wshadow and remaining -Wall -Wextra warnings - #2956

Open
gouarin wants to merge 5 commits into
xtensor-stack:masterfrom
gouarin:fix-shadow-warnings
Open

gouarin wants to merge 5 commits into
xtensor-stack:masterfrom
gouarin:fix-shadow-warnings

Conversation

@gouarin

@gouarin gouarin commented Oct 29, 2026

Copy link
Copy Markdown
Member

Checklist

  • The title and commit message(s) are descriptive.
  • Small commits made to fix your PR have been squashed to avoid history pollution.
  • Tests have been added for new features or bug fixes.
  • 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.

Rename parameters and locals that shadow members, other parameters or
globals:

- xstrided_view and xdynamic_view bring shape(), strides() and layout()
  into scope with using-declarations, so GCC flags constructor and
  stepper parameters with those names. The constructors now take
  view_shape, view_strides and view_layout, and stepper_begin and
  stepper_end take iteration_shape.
- xreducer::element named its local stepper after the stepper member
  type. It is now reducer_stepper.
- reset_buffer in xarray_adaptor and xtensor_adaptor took a parameter
  named pointer, like the member type. It is now buffer.
- The xio printers took a precision parameter, which GCC 13 reports
  against any global named precision (the xio test data defines one).
  The value is the upper bound that init() lowers to the precision the
  data needs, so it is now max_precision.
- The xkeep_slice and xdrop_slice initializer-list constructors used t
  for both the list and the lambda parameter. The lambda now takes
  index.
- XTENSOR_TRY caught the exception as e, which shadows any e in the
  calling scope, such as the xfunction lambda parameters. The macro now
  uses xtensor_check_error.
- test_xarray_adaptor and test_xtensor_adaptor redeclared vec_type with
  the same definition as the namespace-scope alias. Drop the local
  copies.
- test_xbuffer_adaptor reused owner_adaptor for an adaptor with a
  different element type and allocator. Name it size_checked_adaptor.
- test_xmath named its missing value missing, which shadows the
  xt::missing placeholder. Name it missing_value.
- The is_arr lambdas in test_xreducer named their parameter c, like the
  tensor in the enclosing test. They only ever receive shapes, so the
  parameter is now shape.
CHECK_RESULT_TYPE, CHECK_TAG_TYPE and CHECK_TYPE declared a local alias
named result_type. TEST_VALUE_HAS_VALUE declared its own result_type
for the expected type and then passed it to CHECK_RESULT_TYPE, where the
macro's alias shadowed it. The assertion compared the reducer value type
with itself and could not fail.

The macros now name their alias actual_type, and TEST_VALUE_HAS_VALUE
names its alias expected_type. The value_has_value tests now check that
sum() returns double for plain arrays and xoptional<double> for optional
inputs. They pass.
- argsort_iter only reads data_end in assertions. Mark it
  [[maybe_unused]] and drop the (void) idx_end cast, which was dead code
  since idx_end is passed to std::iota.
- The flat argmin and argmax overloads declared a value_type alias they
  never used. Remove it.
- initializer_shape does not read its argument when the shape has no
  dimensions. Mark it [[maybe_unused]].
- accumulate_impl wrapped f in a lambda that was never called for an
  empty tuple. Fold over the assignments directly.
- optional_bitwise combined bool flags with &. The operands are values
  that are already computed, so && gives the same result. It is also
  correct for flag types other than bool, where & could clear a set
  flag (2 & true is 0). The simd path keeps & for batch_bool.
- Remove a stray ';' in xreducer_temporary_type<xoptional>.
- index_mapper was declared as a struct and defined as a class. Declare
  it as a class.
Several tests declared aliases that were used only in some builds, or
not used at all. Where the alias pointed at something worth checking,
the test now checks it:

- The xassign_traits aliases in test_xcomplex, test_xmath,
  test_xstrided_view and test_xview were only read under
  XTENSOR_USE_XSIMD. Without xsimd, simd_linear_assign() is always
  false, so the tests now assert that in an #else branch. The
  assign_traits2 check in test_xview expects false in both builds and
  no longer needs the #if. Note that test_xtensor_core_lib never
  defines XTENSOR_USE_XSIMD, even in an xsimd build.
- test_xview declared carr, a dynamic-rank column-major array, without
  using it. Add the check the column-major is_contiguous_view comment
  describes: such a view is not contiguous because implicit trailing
  all() slices may follow.
- test_xexpression only declared the strides aliases of a shared
  xfunction, one of them under a garbled name. Check that all four
  come from the shape type, as an xfunction has no strides of its own.

Also fix the remaining clang warnings in tests:

- test_xmath tested math::abs(char(1)). Plain char is unsigned on
  aarch64, so the line did not test a signed type there. Use
  signed char with a negative value.
- test_xexpression_holder moved a temporary into the holder, which
  prevents copy elision. Move a named holder instead, which still
  exercises the move constructor.
- test_xsort passed the axis as {0}. Pass 0.
@codspeed

codspeed Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 18.92%

2 warnings

⚠️ Unable to measure the execution of 1 benchmark

This benchmark measured no execution time, so its result is not comparable and counts as unchanged. This usually happens when the compiler removes the code under test.

Prevent compiler optimizations

See affected benchmarks

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 254 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ xshape_access[xt\:\:svector<std\:\:size_t, 4>] 125 ns 154.2 ns -18.92%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing gouarin:fix-shadow-warnings (3ce8ef4) with master (57f3d07)

Open in CodSpeed

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant