From 08baa58598e30765d829b29716b3b2494ea75273 Mon Sep 17 00:00:00 2001 From: Loic Gouarin Date: Thu, 29 Oct 2026 18:56:05 +0100 Subject: [PATCH 1/5] Fix -Wshadow warnings in library headers 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. --- include/xtensor/containers/xarray.hpp | 6 +-- include/xtensor/containers/xtensor.hpp | 6 +-- include/xtensor/io/xio.hpp | 10 ++-- include/xtensor/reducers/xreducer.hpp | 8 +-- include/xtensor/utils/xexception.hpp | 23 ++++---- include/xtensor/views/xdynamic_view.hpp | 39 +++++++------- include/xtensor/views/xslice.hpp | 8 +-- include/xtensor/views/xstrided_view.hpp | 72 ++++++++++++++----------- 8 files changed, 91 insertions(+), 81 deletions(-) diff --git a/include/xtensor/containers/xarray.hpp b/include/xtensor/containers/xarray.hpp index 7f27bd296..1232baf85 100644 --- a/include/xtensor/containers/xarray.hpp +++ b/include/xtensor/containers/xarray.hpp @@ -253,7 +253,7 @@ namespace xt xarray_adaptor& operator=(const xexpression& e); template - void reset_buffer(P&& pointer, S&& size); + void reset_buffer(P&& buffer, S&& size); private: @@ -657,9 +657,9 @@ namespace xt template template - inline void xarray_adaptor::reset_buffer(P&& pointer, S&& size) + inline void xarray_adaptor::reset_buffer(P&& buffer, S&& size) { - return m_storage.reset_data(std::forward

(pointer), std::forward(size)); + return m_storage.reset_data(std::forward

(buffer), std::forward(size)); } } diff --git a/include/xtensor/containers/xtensor.hpp b/include/xtensor/containers/xtensor.hpp index db8d92385..7145ead43 100644 --- a/include/xtensor/containers/xtensor.hpp +++ b/include/xtensor/containers/xtensor.hpp @@ -249,7 +249,7 @@ namespace xt xtensor_adaptor& operator=(const xexpression& e); template - void reset_buffer(P&& pointer, S&& size); + void reset_buffer(P&& buffer, S&& size); private: @@ -720,9 +720,9 @@ namespace xt template template - inline void xtensor_adaptor::reset_buffer(P&& pointer, S&& size) + inline void xtensor_adaptor::reset_buffer(P&& buffer, S&& size) { - return m_storage.reset_data(std::forward

(pointer), std::forward(size)); + return m_storage.reset_data(std::forward

(buffer), std::forward(size)); } /******************************* diff --git a/include/xtensor/io/xio.hpp b/include/xtensor/io/xio.hpp index 09ee4da58..769e2f986 100644 --- a/include/xtensor/io/xio.hpp +++ b/include/xtensor/io/xio.hpp @@ -302,8 +302,8 @@ namespace xt using cache_type = std::vector; using cache_iterator = typename cache_type::const_iterator; - explicit printer(std::streamsize precision) - : m_precision(precision) + explicit printer(std::streamsize max_precision) + : m_precision(max_precision) { } @@ -554,9 +554,9 @@ namespace xt using cache_type = std::vector; using cache_iterator = typename cache_type::const_iterator; - explicit printer(std::streamsize precision) - : real_printer(precision) - , imag_printer(precision) + explicit printer(std::streamsize max_precision) + : real_printer(max_precision) + , imag_printer(max_precision) { } diff --git a/include/xtensor/reducers/xreducer.hpp b/include/xtensor/reducers/xreducer.hpp index e99522b5e..2c292eb9d 100644 --- a/include/xtensor/reducers/xreducer.hpp +++ b/include/xtensor/reducers/xreducer.hpp @@ -1552,7 +1552,7 @@ namespace xt inline auto xreducer::element(It first, It last) const -> const_reference { XTENSOR_TRY(check_element_index(shape(), first, last)); - auto stepper = const_stepper(*this, 0); + auto reducer_stepper = const_stepper(*this, 0); if (first != last) { size_type dim = 0; @@ -1563,16 +1563,16 @@ namespace xt { if (begin < first) { - stepper.step(dim++, std::size_t(0)); + reducer_stepper.step(dim++, std::size_t(0)); begin++; } else { - stepper.step(dim++, std::size_t(*begin++)); + reducer_stepper.step(dim++, std::size_t(*begin++)); } } } - return *stepper; + return *reducer_stepper; } /** diff --git a/include/xtensor/utils/xexception.hpp b/include/xtensor/utils/xexception.hpp index 025836ce2..c9c7ee51f 100644 --- a/include/xtensor/utils/xexception.hpp +++ b/include/xtensor/utils/xexception.hpp @@ -310,17 +310,18 @@ namespace xt #if (defined(XTENSOR_ENABLE_ASSERT) && !defined(XTENSOR_DISABLE_EXCEPTIONS)) #define XTENSOR_TRY(expr) XTENSOR_TRY_IMPL(expr, __FILE__, __LINE__) -#define XTENSOR_TRY_IMPL(expr, file, line) \ - try \ - { \ - expr; \ - } \ - catch (std::exception & e) \ - { \ - XTENSOR_THROW( \ - std::runtime_error, \ - std::string(file) + ':' + std::to_string(line) + ": check failed\n\t" + std::string(e.what()) \ - ); \ +#define XTENSOR_TRY_IMPL(expr, file, line) \ + try \ + { \ + expr; \ + } \ + catch (std::exception & xtensor_check_error) \ + { \ + XTENSOR_THROW( \ + std::runtime_error, \ + std::string(file) + ':' + std::to_string(line) + ": check failed\n\t" \ + + std::string(xtensor_check_error.what()) \ + ); \ } #else #define XTENSOR_TRY(expr) diff --git a/include/xtensor/views/xdynamic_view.hpp b/include/xtensor/views/xdynamic_view.hpp index 777ec66d3..7eb7d85b6 100644 --- a/include/xtensor/views/xdynamic_view.hpp +++ b/include/xtensor/views/xdynamic_view.hpp @@ -150,10 +150,10 @@ namespace xt template xdynamic_view( CTA&& e, - SA&& shape, - get_strides_t&& strides, + SA&& view_shape, + get_strides_t&& view_strides, std::size_t offset, - layout_type layout, + layout_type view_layout, slice_vector_type&& slices, get_strides_t&& adj_strides ) noexcept; @@ -225,14 +225,14 @@ namespace xt void fill(const T& value); template - stepper stepper_begin(const ST& shape); + stepper stepper_begin(const ST& iteration_shape); template - stepper stepper_end(const ST& shape, layout_type l); + stepper stepper_end(const ST& iteration_shape, layout_type l); template - const_stepper stepper_begin(const ST& shape) const; + const_stepper stepper_begin(const ST& iteration_shape) const; template - const_stepper stepper_end(const ST& shape, layout_type l) const; + const_stepper stepper_end(const ST& iteration_shape, layout_type l) const; using container_iterator = std:: conditional_t; @@ -383,14 +383,14 @@ namespace xt template inline xdynamic_view::xdynamic_view( CTA&& e, - SA&& shape, - get_strides_t&& strides, + SA&& view_shape, + get_strides_t&& view_strides, std::size_t offset, - layout_type layout, + layout_type view_layout, slice_vector_type&& slices, get_strides_t&& adj_strides ) noexcept - : base_type(std::forward(e), std::forward(shape), std::move(strides), offset, layout) + : base_type(std::forward(e), std::forward(view_shape), std::move(view_strides), offset, view_layout) , m_slices(std::move(slices)) , m_adj_strides(std::move(adj_strides)) { @@ -525,34 +525,35 @@ namespace xt template template - inline auto xdynamic_view::stepper_begin(const ST& shape) -> stepper + inline auto xdynamic_view::stepper_begin(const ST& iteration_shape) -> stepper { - size_type offset = shape.size() - dimension(); + size_type offset = iteration_shape.size() - dimension(); return stepper(this, offset); } template template - inline auto xdynamic_view::stepper_end(const ST& shape, layout_type /*l*/) -> stepper + inline auto xdynamic_view::stepper_end(const ST& iteration_shape, layout_type /*l*/) + -> stepper { - size_type offset = shape.size() - dimension(); + size_type offset = iteration_shape.size() - dimension(); return stepper(this, offset, true); } template template - inline auto xdynamic_view::stepper_begin(const ST& shape) const -> const_stepper + inline auto xdynamic_view::stepper_begin(const ST& iteration_shape) const -> const_stepper { - size_type offset = shape.size() - dimension(); + size_type offset = iteration_shape.size() - dimension(); return const_stepper(this, offset); } template template - inline auto xdynamic_view::stepper_end(const ST& shape, layout_type /*l*/) const + inline auto xdynamic_view::stepper_end(const ST& iteration_shape, layout_type /*l*/) const -> const_stepper { - size_type offset = shape.size() - dimension(); + size_type offset = iteration_shape.size() - dimension(); return const_stepper(this, offset, true); } diff --git a/include/xtensor/views/xslice.hpp b/include/xtensor/views/xslice.hpp index 6cd2865a4..c1ac83bb2 100644 --- a/include/xtensor/views/xslice.hpp +++ b/include/xtensor/views/xslice.hpp @@ -1301,9 +1301,9 @@ namespace xt t.begin(), t.end(), m_raw_indices.begin(), - [](auto t) + [](auto index) { - return static_cast(t); + return static_cast(index); } ); } @@ -1445,9 +1445,9 @@ namespace xt t.begin(), t.end(), m_raw_indices.begin(), - [](auto t) + [](auto index) { - return static_cast(t); + return static_cast(index); } ); } diff --git a/include/xtensor/views/xstrided_view.hpp b/include/xtensor/views/xstrided_view.hpp index b0fe2c6e0..f2deef640 100644 --- a/include/xtensor/views/xstrided_view.hpp +++ b/include/xtensor/views/xstrided_view.hpp @@ -188,7 +188,13 @@ namespace xt decltype(std::declval()[0])>; template - xstrided_view(CTA&& e, SA&& shape, strides_type&& strides, std::size_t offset, layout_type layout) noexcept; + xstrided_view( + CTA&& e, + SA&& view_shape, + strides_type&& view_strides, + std::size_t offset, + layout_type view_layout + ) noexcept; xstrided_view(const xstrided_view& rhs) = default; @@ -239,24 +245,24 @@ namespace xt const_reverse_linear_iterator linear_crend() const; template - disable_indexed_stepper_t stepper_begin(const ST& shape); + disable_indexed_stepper_t stepper_begin(const ST& iteration_shape); template - disable_indexed_stepper_t stepper_end(const ST& shape, layout_type l); + disable_indexed_stepper_t stepper_end(const ST& iteration_shape, layout_type l); template - enable_indexed_stepper_t stepper_begin(const ST& shape); + enable_indexed_stepper_t stepper_begin(const ST& iteration_shape); template - enable_indexed_stepper_t stepper_end(const ST& shape, layout_type l); + enable_indexed_stepper_t stepper_end(const ST& iteration_shape, layout_type l); template - disable_indexed_stepper_t stepper_begin(const ST& shape) const; + disable_indexed_stepper_t stepper_begin(const ST& iteration_shape) const; template - disable_indexed_stepper_t stepper_end(const ST& shape, layout_type l) const; + disable_indexed_stepper_t stepper_end(const ST& iteration_shape, layout_type l) const; template - enable_indexed_stepper_t stepper_begin(const ST& shape) const; + enable_indexed_stepper_t stepper_begin(const ST& iteration_shape) const; template - enable_indexed_stepper_t stepper_end(const ST& shape, layout_type l) const; + enable_indexed_stepper_t stepper_end(const ST& iteration_shape, layout_type l) const; template using simd_return_type = xt_simd::simd_return_type; @@ -363,21 +369,21 @@ namespace xt * Constructs an xstrided_view * * @param e the underlying xexpression for this view - * @param shape the shape of the view - * @param strides the strides of the view + * @param view_shape the shape of the view + * @param view_strides the strides of the view * @param offset the offset of the first element in the underlying container - * @param layout the layout of the view + * @param view_layout the layout of the view */ template template inline xstrided_view::xstrided_view( CTA&& e, - SA&& shape, - strides_type&& strides, + SA&& view_shape, + strides_type&& view_strides, std::size_t offset, - layout_type layout + layout_type view_layout ) noexcept - : base_type(std::forward(e), std::forward(shape), std::move(strides), offset, layout) + : base_type(std::forward(e), std::forward(view_shape), std::move(view_strides), offset, view_layout) { } @@ -565,71 +571,73 @@ namespace xt template template - inline auto xstrided_view::stepper_begin(const ST& shape) -> disable_indexed_stepper_t + inline auto xstrided_view::stepper_begin(const ST& iteration_shape) + -> disable_indexed_stepper_t { - size_type offset = shape.size() - dimension(); + size_type offset = iteration_shape.size() - dimension(); return stepper(this, data_xbegin(), offset); } template template - inline auto xstrided_view::stepper_end(const ST& shape, layout_type l) + inline auto xstrided_view::stepper_end(const ST& iteration_shape, layout_type l) -> disable_indexed_stepper_t { - size_type offset = shape.size() - dimension(); + size_type offset = iteration_shape.size() - dimension(); return stepper(this, data_xend(l, offset), offset); } template template - inline auto xstrided_view::stepper_begin(const ST& shape) -> enable_indexed_stepper_t + inline auto xstrided_view::stepper_begin(const ST& iteration_shape) + -> enable_indexed_stepper_t { - size_type offset = shape.size() - dimension(); + size_type offset = iteration_shape.size() - dimension(); return stepper(this, offset); } template template - inline auto xstrided_view::stepper_end(const ST& shape, layout_type /*l*/) + inline auto xstrided_view::stepper_end(const ST& iteration_shape, layout_type /*l*/) -> enable_indexed_stepper_t { - size_type offset = shape.size() - dimension(); + size_type offset = iteration_shape.size() - dimension(); return stepper(this, offset, true); } template template - inline auto xstrided_view::stepper_begin(const ST& shape) const + inline auto xstrided_view::stepper_begin(const ST& iteration_shape) const -> disable_indexed_stepper_t { - size_type offset = shape.size() - dimension(); + size_type offset = iteration_shape.size() - dimension(); return const_stepper(this, data_xbegin(), offset); } template template - inline auto xstrided_view::stepper_end(const ST& shape, layout_type l) const + inline auto xstrided_view::stepper_end(const ST& iteration_shape, layout_type l) const -> disable_indexed_stepper_t { - size_type offset = shape.size() - dimension(); + size_type offset = iteration_shape.size() - dimension(); return const_stepper(this, data_xend(l, offset), offset); } template template - inline auto xstrided_view::stepper_begin(const ST& shape) const + inline auto xstrided_view::stepper_begin(const ST& iteration_shape) const -> enable_indexed_stepper_t { - size_type offset = shape.size() - dimension(); + size_type offset = iteration_shape.size() - dimension(); return const_stepper(this, offset); } template template - inline auto xstrided_view::stepper_end(const ST& shape, layout_type /*l*/) const + inline auto xstrided_view::stepper_end(const ST& iteration_shape, layout_type /*l*/) const -> enable_indexed_stepper_t { - size_type offset = shape.size() - dimension(); + size_type offset = iteration_shape.size() - dimension(); return const_stepper(this, offset, true); } From e592cbbcb5e39d30b8aeb1f837b44303429b396a Mon Sep 17 00:00:00 2001 From: Loic Gouarin Date: Thu, 29 Oct 2026 18:56:30 +0100 Subject: [PATCH 2/5] Fix -Wshadow warnings in tests - 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. --- test/test_xarray_adaptor.cpp | 1 - test/test_xbuffer_adaptor.cpp | 6 +++--- test/test_xmath.cpp | 26 +++++++++++++------------- test/test_xreducer.cpp | 8 ++++---- test/test_xtensor_adaptor.cpp | 1 - 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/test/test_xarray_adaptor.cpp b/test/test_xarray_adaptor.cpp index 5142386f8..7ffbc5c63 100644 --- a/test/test_xarray_adaptor.cpp +++ b/test/test_xarray_adaptor.cpp @@ -191,7 +191,6 @@ namespace xt TEST(xarray_adaptor, iterator_types) { - using vec_type = std::vector; using array_type = xarray_adaptor; using const_array_type = xarray_adaptor; using iterator = vec_type::iterator; diff --git a/test/test_xbuffer_adaptor.cpp b/test/test_xbuffer_adaptor.cpp index 5b0a5fcb6..018870227 100644 --- a/test/test_xbuffer_adaptor.cpp +++ b/test/test_xbuffer_adaptor.cpp @@ -95,14 +95,14 @@ namespace xt TEST(xbuffer_adaptor, owner_move_assign_check_size) { size_check_allocator custom_allocator; - using owner_adaptor = xbuffer_adaptor; + using size_checked_adaptor = xbuffer_adaptor; size_t size1 = 100; size_t* data1 = custom_allocator.allocate(size1); - owner_adaptor adapt1(data1, size1); + size_checked_adaptor adapt1(data1, size1); size_t size2 = 200; size_t* data2 = custom_allocator.allocate(size2); - owner_adaptor adapt2(data2, size2); + size_checked_adaptor adapt2(data2, size2); adapt1 = adapt2; EXPECT_EQ(adapt1.size(), size2); diff --git a/test/test_xmath.cpp b/test/test_xmath.cpp index 57771859b..088ad4c66 100644 --- a/test/test_xmath.cpp +++ b/test/test_xmath.cpp @@ -170,55 +170,55 @@ namespace xt TEST(xmath, minimum) { using opt_type = xoptional_assembly, xarray>; - auto missing = xtl::missing(); + auto missing_value = xtl::missing(); xarray a = {1, 2, 3, 4, 5, 6}; xarray b = {6, 5, 4, 3, 2, 1}; - opt_type opt_a = {1, missing, 3, 4, 5, missing}; - opt_type opt_b = {6, 5, 4, 3, missing, 1}; + opt_type opt_a = {1, missing_value, 3, 4, 5, missing_value}; + opt_type opt_b = {6, 5, 4, 3, missing_value, 1}; xarray res = {1, 2, 3, 3, 2, 1}; EXPECT_EQ(res, minimum(a, b)); - opt_type res1 = {1, missing, 3, 3, 2, missing}; + opt_type res1 = {1, missing_value, 3, 3, 2, missing_value}; EXPECT_EQ(res1, minimum(opt_a, b)); - opt_type res2 = {1, missing, 3, 3, missing, missing}; + opt_type res2 = {1, missing_value, 3, 3, missing_value, missing_value}; EXPECT_EQ(res2, minimum(opt_a, opt_b)); } TEST(xmath, maximum) { using opt_type = xoptional_assembly, xarray>; - auto missing = xtl::missing(); + auto missing_value = xtl::missing(); xarray a = {1, 2, 3, 4, 5, 6}; xarray b = {6, 5, 4, 3, 2, 1}; - opt_type opt_a = {1, missing, 3, 4, 5, missing}; - opt_type opt_b = {6, 5, 4, 3, missing, 1}; + opt_type opt_a = {1, missing_value, 3, 4, 5, missing_value}; + opt_type opt_b = {6, 5, 4, 3, missing_value, 1}; xarray res = {6, 5, 4, 4, 5, 6}; EXPECT_EQ(res, maximum(a, b)); - opt_type res1 = {6, missing, 4, 4, 5, missing}; + opt_type res1 = {6, missing_value, 4, 4, 5, missing_value}; EXPECT_EQ(res1, maximum(opt_a, b)); - opt_type res2 = {6, missing, 4, 4, missing, missing}; + opt_type res2 = {6, missing_value, 4, 4, missing_value, missing_value}; EXPECT_EQ(res2, maximum(opt_a, opt_b)); } TEST(xmath, clip) { using opt_type = xoptional_assembly, xarray>; - auto missing = xtl::missing(); + auto missing_value = xtl::missing(); xarray a = {1, 2, 3, 4, 5, 6}; - opt_type opt_a = {1, missing, 3, 4, 5, missing}; + opt_type opt_a = {1, missing_value, 3, 4, 5, missing_value}; xarray res = {2, 2, 3, 4, 4, 4}; EXPECT_EQ(res, clip(a, 2.0, 4.0)); - opt_type res1 = {2, missing, 3, 4, 4, missing}; + opt_type res1 = {2, missing_value, 3, 4, 4, missing_value}; EXPECT_EQ(res1, clip(opt_a, 2.0, 4.0)); } diff --git a/test/test_xreducer.cpp b/test/test_xreducer.cpp index aa0a824b5..c1ff54c29 100644 --- a/test/test_xreducer.cpp +++ b/test/test_xreducer.cpp @@ -784,9 +784,9 @@ namespace xt { xtensor c = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}; auto xa = xt::sum(c, {0}, evaluation_strategy::immediate); - auto is_arr = [](const auto& c) + auto is_arr = [](const auto& shape) { - bool istrue = detail::is_array>::value; + bool istrue = detail::is_array>::value; return istrue; }; @@ -826,9 +826,9 @@ namespace xt b.resize({3, 3, 3}); std::iota(b.storage().begin(), b.storage().end(), 0); - auto is_arr = [](const auto& c) + auto is_arr = [](const auto& shape) { - bool istrue = detail::is_array>::value; + bool istrue = detail::is_array>::value; return istrue; }; diff --git a/test/test_xtensor_adaptor.cpp b/test/test_xtensor_adaptor.cpp index 5bbc5c0d3..a86d1da40 100644 --- a/test/test_xtensor_adaptor.cpp +++ b/test/test_xtensor_adaptor.cpp @@ -192,7 +192,6 @@ namespace xt TEST(xtensor_adaptor, iterator_types) { - using vec_type = std::vector; using tensor_type = xtensor_adaptor; using const_tensor_type = xtensor_adaptor; using iterator = vec_type::iterator; From a57bcc1db73698c785971dd0414af43ceab4c794 Mon Sep 17 00:00:00 2001 From: Loic Gouarin Date: Thu, 29 Oct 2026 18:56:36 +0100 Subject: [PATCH 3/5] Make reducer type checks compare against the expected type 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 for optional inputs. They pass. --- test/test_xreducer.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/test_xreducer.cpp b/test/test_xreducer.cpp index c1ff54c29..7fca4b51d 100644 --- a/test/test_xreducer.cpp +++ b/test/test_xreducer.cpp @@ -36,20 +36,20 @@ namespace xt #define CHECK_RESULT_TYPE(EXPRESSION, EXPECTED_TYPE) \ { \ - using result_type = typename std::decay_t::value_type; \ - EXPECT_TRUE((std::is_same::value)); \ + using actual_type = typename std::decay_t::value_type; \ + EXPECT_TRUE((std::is_same::value)); \ } #define CHECK_TAG_TYPE(EXPRESSION, EXPECTED_TYPE) \ { \ - using result_type = typename std::decay_t::expression_tag; \ - EXPECT_TRUE((std::is_same::value)); \ + using actual_type = typename std::decay_t::expression_tag; \ + EXPECT_TRUE((std::is_same::value)); \ } #define CHECK_TYPE(VALUE, EXPECTED_TYPE) \ { \ - using result_type = typename std::decay_t; \ - EXPECT_TRUE((std::is_same::value)); \ + using actual_type = typename std::decay_t; \ + EXPECT_TRUE((std::is_same::value)); \ } struct xreducer_features @@ -155,13 +155,13 @@ namespace xt #undef TEST_EXPRESSION_TAG -#define TEST_VALUE_HAS_VALUE(INPUT, V_TYPE, OPTIONAL) \ - using result_type = std::conditional_t, double>; \ - \ - auto res = xt::sum(INPUT, feats.m_axes); \ - CHECK_RESULT_TYPE(res, result_type); \ - CHECK_TYPE(xt::value(res)(1, 1, 1), V_TYPE); \ - EXPECT_EQ(!OPTIONAL, xt::has_value(res)(0, 0, 0)); \ +#define TEST_VALUE_HAS_VALUE(INPUT, V_TYPE, OPTIONAL) \ + using expected_type = std::conditional_t, double>; \ + \ + auto res = xt::sum(INPUT, feats.m_axes); \ + CHECK_RESULT_TYPE(res, expected_type); \ + CHECK_TYPE(xt::value(res)(1, 1, 1), V_TYPE); \ + EXPECT_EQ(!OPTIONAL, xt::has_value(res)(0, 0, 0)); \ EXPECT_TRUE(xt::has_value(res)(1, 1, 1)); TEST(xreducer, value_has_value) From 6c8daf45f0dc8c8956901791e367fe3edcfc2975 Mon Sep 17 00:00:00 2001 From: Loic Gouarin Date: Thu, 29 Oct 2026 18:57:01 +0100 Subject: [PATCH 4/5] Fix unused, extra-semi, mismatched-tags and bitwise warnings in headers - 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. - index_mapper was declared as a struct and defined as a class. Declare it as a class. --- include/xtensor/core/xshape.hpp | 2 +- include/xtensor/misc/xsort.hpp | 5 +---- include/xtensor/optional/xoptional.hpp | 3 +-- include/xtensor/utils/xutils.hpp | 6 +----- include/xtensor/views/index_mapper.hpp | 2 +- 5 files changed, 5 insertions(+), 13 deletions(-) diff --git a/include/xtensor/core/xshape.hpp b/include/xtensor/core/xshape.hpp index 1380f4e07..36dfd2a7d 100644 --- a/include/xtensor/core/xshape.hpp +++ b/include/xtensor/core/xshape.hpp @@ -197,7 +197,7 @@ namespace xt }; template - constexpr R initializer_shape(U t, std::index_sequence) + constexpr R initializer_shape([[maybe_unused]] U t, std::index_sequence) { using size_type = typename R::value_type; return {size_type(initializer_shape_impl::value(t))...}; diff --git a/include/xtensor/misc/xsort.hpp b/include/xtensor/misc/xsort.hpp index 196ec45cd..619bbb6de 100644 --- a/include/xtensor/misc/xsort.hpp +++ b/include/xtensor/misc/xsort.hpp @@ -294,7 +294,7 @@ namespace xt template inline void argsort_iter( ConstRandomIt data_begin, - ConstRandomIt data_end, + [[maybe_unused]] ConstRandomIt data_end, RandomIt idx_begin, RandomIt idx_end, Compare comp, @@ -303,7 +303,6 @@ namespace xt { XTENSOR_ASSERT(std::distance(data_begin, data_end) >= 0); XTENSOR_ASSERT(std::distance(idx_begin, idx_end) == std::distance(data_begin, data_end)); - (void) idx_end; // TODO(C++17) [[maybe_unused]] only used in assertion. std::iota(idx_begin, idx_end, 0); switch (method) @@ -1237,7 +1236,6 @@ namespace xt template inline auto argmin(const xexpression& e) { - using value_type = typename E::value_type; auto&& ed = eval(e.derived_cast()); auto begin = ed.template begin(); auto end = ed.template end(); @@ -1267,7 +1265,6 @@ namespace xt template inline auto argmax(const xexpression& e) { - using value_type = typename E::value_type; auto&& ed = eval(e.derived_cast()); auto begin = ed.template begin(); auto end = ed.template end(); diff --git a/include/xtensor/optional/xoptional.hpp b/include/xtensor/optional/xoptional.hpp index 6c690b0d6..38c870e54 100644 --- a/include/xtensor/optional/xoptional.hpp +++ b/include/xtensor/optional/xoptional.hpp @@ -199,7 +199,7 @@ namespace xt template constexpr result_type apply_impl(const U& t, const Args&... args) const { - return t & apply_impl(args...); + return t && apply_impl(args...); } template @@ -242,7 +242,6 @@ namespace xt struct xreducer_temporary_type> { using type = xtl::xoptional, bool>; - ; }; } diff --git a/include/xtensor/utils/xutils.hpp b/include/xtensor/utils/xutils.hpp index ed4a04f48..943dd0e77 100644 --- a/include/xtensor/utils/xutils.hpp +++ b/include/xtensor/utils/xutils.hpp @@ -193,11 +193,7 @@ namespace xt ) { R res = init; - auto wrapper = [&](const auto& i, const auto& j) - { - res = f(i, j); - }; - (wrapper(res, std::get(t)), ...); + ((res = f(res, std::get(t))), ...); return res; } } diff --git a/include/xtensor/views/index_mapper.hpp b/include/xtensor/views/index_mapper.hpp index d445ac1ec..a3d4288de 100644 --- a/include/xtensor/views/index_mapper.hpp +++ b/include/xtensor/views/index_mapper.hpp @@ -18,7 +18,7 @@ namespace xt { template - struct index_mapper; + class index_mapper; /** * @enum access_t From 3ce8ef4e4b3de8dadcf18c4cab8bb166cd43cf4f Mon Sep 17 00:00:00 2001 From: Loic Gouarin Date: Thu, 29 Oct 2026 18:57:08 +0100 Subject: [PATCH 5/5] Turn unused aliases in tests into assertions 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. --- test/test_xcomplex.cpp | 8 ++++++++ test/test_xexpression.cpp | 12 +++++++----- test/test_xexpression_holder.cpp | 3 ++- test/test_xmath.cpp | 4 +++- test/test_xsort.cpp | 2 +- test/test_xstrided_view.cpp | 2 ++ test/test_xview.cpp | 6 +++--- 7 files changed, 26 insertions(+), 11 deletions(-) diff --git a/test/test_xcomplex.cpp b/test/test_xcomplex.cpp index 920d21b8e..2281b0c3e 100644 --- a/test/test_xcomplex.cpp +++ b/test/test_xcomplex.cpp @@ -137,6 +137,8 @@ namespace xt #if XTENSOR_USE_XSIMD EXPECT_TRUE(assign_t_angle::simd_linear_assign()); +#else + EXPECT_FALSE(assign_t_angle::simd_linear_assign()); #endif auto cmplres_conj = xt::conj(cmplarg_0); @@ -155,6 +157,8 @@ namespace xt static_cast(b1); static_cast(b2); EXPECT_TRUE(assign_t_conj::simd_linear_assign()); +#else + EXPECT_FALSE(assign_t_conj::simd_linear_assign()); #endif auto cmplres_norm = xt::norm(cmplarg_0); @@ -168,6 +172,8 @@ namespace xt #if XTENSOR_USE_XSIMD EXPECT_TRUE(assign_t_norm::simd_linear_assign()); +#else + EXPECT_FALSE(assign_t_norm::simd_linear_assign()); #endif EXPECT_TRUE(allclose(fieldnorm, cmplres_norm)); @@ -196,6 +202,8 @@ namespace xt #if XTENSOR_USE_XSIMD EXPECT_TRUE(assign_t_arg::simd_linear_assign()); +#else + EXPECT_FALSE(assign_t_arg::simd_linear_assign()); #endif } diff --git a/test/test_xexpression.cpp b/test/test_xexpression.cpp index 75eba3edb..9eefdde39 100644 --- a/test/test_xexpression.cpp +++ b/test/test_xexpression.cpp @@ -102,13 +102,15 @@ namespace xt buffer << expr1; EXPECT_EQ(buffer.str(), "{{ 2., 4., 6., 8.},\n { 10., 12., 14., 16.}}"); - // Compilation test + // An xfunction has no strides of its own, so the shared expression + // derives all its strides types from its shape type. auto sexpr1 = make_xshared(std::move(expr1)); using expr_type = decltype(sexpr1); - using strides_type = typename expr_type::strides_type; - using inner_strides_type = typename expr_type::inner_strides_type; - using backstrides_type = typename expr_type::backstrides_type; - using inner_strides_tybackstrides_typepe = typename expr_type::inner_backstrides_type; + using expected_strides_type = get_strides_type::type; + EXPECT_TRUE((std::is_same::value)); + EXPECT_TRUE((std::is_same::value)); + EXPECT_TRUE((std::is_same::value)); + EXPECT_TRUE((std::is_same::value)); } TEST(xexpression, shared_expr_return) diff --git a/test/test_xexpression_holder.cpp b/test/test_xexpression_holder.cpp index cff5d6fb6..0bf4bfd24 100644 --- a/test/test_xexpression_holder.cpp +++ b/test/test_xexpression_holder.cpp @@ -24,7 +24,8 @@ namespace xt xexpression_holder holder_a = xexpression_holder(a); xexpression_holder holder_b(b); - xexpression_holder holder_c(std::move(xexpression_holder(c))); + xexpression_holder holder_tmp(c); + xexpression_holder holder_c(std::move(holder_tmp)); } TEST(xexpression_holder, assign) diff --git a/test/test_xmath.cpp b/test/test_xmath.cpp index 088ad4c66..982e71a1a 100644 --- a/test/test_xmath.cpp +++ b/test/test_xmath.cpp @@ -47,6 +47,8 @@ namespace xt #if XTENSOR_USE_XSIMD EXPECT_TRUE(assign_traits::simd_linear_assign()); +#else + EXPECT_FALSE(assign_traits::simd_linear_assign()); #endif } @@ -743,7 +745,7 @@ namespace xt EXPECT_EQ(math::abs(1ul), 1ul); EXPECT_EQ(math::abs(1u), 1u); EXPECT_EQ(math::abs(static_cast(1)), static_cast(1)); - EXPECT_EQ(math::abs(char(1)), 1); + EXPECT_EQ(math::abs(static_cast(-1)), 1); EXPECT_EQ(math::abs(int(1)), 1); EXPECT_EQ(math::abs(int(-1)), 1); EXPECT_EQ(math::abs(long(-1)), long(1)); diff --git a/test/test_xsort.cpp b/test/test_xsort.cpp index bbe928d4d..c8f9dc143 100644 --- a/test/test_xsort.cpp +++ b/test/test_xsort.cpp @@ -173,7 +173,7 @@ namespace xt 47, 41, 40, 34, 33, 43, 64 }; - EXPECT_EQ(ex, xt::argsort(a, {0}, xt::sorting_method::stable)); + EXPECT_EQ(ex, xt::argsort(a, 0, xt::sorting_method::stable)); } TEST(xsort, sort_easy) diff --git a/test/test_xstrided_view.cpp b/test/test_xstrided_view.cpp index b916d2473..8f7dbeffe 100644 --- a/test/test_xstrided_view.cpp +++ b/test/test_xstrided_view.cpp @@ -691,6 +691,8 @@ namespace xt #if XTENSOR_USE_XSIMD EXPECT_TRUE(assign_traits::simd_linear_assign()); +#else + EXPECT_FALSE(assign_traits::simd_linear_assign()); #endif EXPECT_EQ(av, e); diff --git a/test/test_xview.cpp b/test/test_xview.cpp index 8069bb016..3d5478a84 100644 --- a/test/test_xview.cpp +++ b/test/test_xview.cpp @@ -1360,6 +1360,7 @@ namespace xt EXPECT_TRUE((detail::is_contiguous_view, xall, int, int>())); EXPECT_TRUE((detail::is_contiguous_view, xall, int, int>())); + EXPECT_FALSE((detail::is_contiguous_view, xall, int, int>())); EXPECT_FALSE((detail::is_contiguous_view, xall, int, int>())); EXPECT_TRUE((detail::is_contiguous_view, xall, xrange, int>())); EXPECT_FALSE((detail::is_contiguous_view, xrange, xrange, int>())); @@ -1477,13 +1478,12 @@ namespace xt #if XTENSOR_USE_XSIMD EXPECT_TRUE(assign_traits::simd_linear_assign()); +#else + EXPECT_FALSE(assign_traits::simd_linear_assign()); #endif using assign_traits2 = xassign_traits; - -#if XTENSOR_USE_XSIMD EXPECT_FALSE(assign_traits2::simd_linear_assign()); -#endif } }