From 9c68fbdc070f08b78333ae8310f64d01e3fd88be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Offringa?= Date: Thu, 1 Aug 2024 16:24:45 +0200 Subject: [PATCH 1/3] Fix various compiler warnings These solve warnings when compiled with gcc 14 using a set of warnings enabled that we use in one of our projects: -Wall -Wnon-virtual-dtor -Wzero-as-null-pointer-constant -Wduplicated-branches -Wundef -Wvla -Wpointer-arith -Wextra -Wno-unused-parameter --- include/xtensor/xassign.hpp | 25 +++++++++++++++---------- include/xtensor/xfixed.hpp | 2 +- include/xtensor/xsort.hpp | 2 -- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/include/xtensor/xassign.hpp b/include/xtensor/xassign.hpp index 2ec698ae6..6d3d02cf7 100644 --- a/include/xtensor/xassign.hpp +++ b/include/xtensor/xassign.hpp @@ -456,16 +456,21 @@ namespace xt constexpr bool simd_strided_assign = traits::simd_strided_assign(); if (linear_assign) { - if (simd_linear_assign || traits::simd_linear_assign(de1, de2)) - { - // Do not use linear_assigner here since it will make the compiler - // instantiate this branch even if the runtime condition is false, resulting - // in compilation error for expressions that do not provide a SIMD interface. - // simd_assign is true if simd_linear_assign() or simd_linear_assign(de1, de2) - // is true. - linear_assigner::run(de1, de2); - } - else + // Do not use linear_assigner here since it will make the compiler + // instantiate this branch even if the runtime condition is false, resulting + // in compilation error for expressions that do not provide a SIMD interface. + // simd_assign is true if simd_linear_assign() or simd_linear_assign(de1, de2) + // is true. + if constexpr(simd_assign) { + if(simd_linear_assign || traits::simd_linear_assign(de1, de2)) + { + linear_assigner::run(de1, de2); + } + else + { + linear_assigner::run(de1, de2); + } + } else { linear_assigner::run(de1, de2); } diff --git a/include/xtensor/xfixed.hpp b/include/xtensor/xfixed.hpp index c6ba964ed..36e9910d3 100644 --- a/include/xtensor/xfixed.hpp +++ b/include/xtensor/xfixed.hpp @@ -153,7 +153,7 @@ namespace xt (L == layout_type::row_major) || (L == layout_type::column_major), "Layout not supported for fixed array" ); -#if (_MSC_VER >= 1910) +#if (defined(_MSC_VER_) && _MSC_VER >= 1910) using temp_type = std::index_sequence; return R({workaround::get_computed_strides(shape[I] == 1)...}); #else diff --git a/include/xtensor/xsort.hpp b/include/xtensor/xsort.hpp index 95591a798..a539c7dc9 100644 --- a/include/xtensor/xsort.hpp +++ b/include/xtensor/xsort.hpp @@ -1242,7 +1242,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(); @@ -1272,7 +1271,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(); From 64996572319a85f23da6b27134cefc780f0ee31f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Offringa?= Date: Fri, 22 Nov 2024 08:24:29 +0100 Subject: [PATCH 2/3] Solve warning without using C++17 --- include/xtensor/xassign.hpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/include/xtensor/xassign.hpp b/include/xtensor/xassign.hpp index 6d3d02cf7..ca53f129d 100644 --- a/include/xtensor/xassign.hpp +++ b/include/xtensor/xassign.hpp @@ -456,24 +456,22 @@ namespace xt constexpr bool simd_strided_assign = traits::simd_strided_assign(); if (linear_assign) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wduplicated-branches" + if(simd_linear_assign || traits::simd_linear_assign(de1, de2)) + { // Do not use linear_assigner here since it will make the compiler // instantiate this branch even if the runtime condition is false, resulting // in compilation error for expressions that do not provide a SIMD interface. // simd_assign is true if simd_linear_assign() or simd_linear_assign(de1, de2) // is true. - if constexpr(simd_assign) { - if(simd_linear_assign || traits::simd_linear_assign(de1, de2)) - { - linear_assigner::run(de1, de2); + linear_assigner::run(de1, de2); } else { linear_assigner::run(de1, de2); } - } else - { - linear_assigner::run(de1, de2); - } +#pragma GCC diagnostic pop } else if (simd_strided_assign) { From a8ec29a34371ef1ee19ed38dc523650f90161170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Offringa?= Date: Fri, 22 Nov 2024 08:26:04 +0100 Subject: [PATCH 3/3] Undo whitespace changes --- include/xtensor/xassign.hpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/include/xtensor/xassign.hpp b/include/xtensor/xassign.hpp index ca53f129d..703634c2f 100644 --- a/include/xtensor/xassign.hpp +++ b/include/xtensor/xassign.hpp @@ -458,19 +458,19 @@ namespace xt { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wduplicated-branches" - if(simd_linear_assign || traits::simd_linear_assign(de1, de2)) + if (simd_linear_assign || traits::simd_linear_assign(de1, de2)) { - // Do not use linear_assigner here since it will make the compiler - // instantiate this branch even if the runtime condition is false, resulting - // in compilation error for expressions that do not provide a SIMD interface. - // simd_assign is true if simd_linear_assign() or simd_linear_assign(de1, de2) - // is true. + // Do not use linear_assigner here since it will make the compiler + // instantiate this branch even if the runtime condition is false, resulting + // in compilation error for expressions that do not provide a SIMD interface. + // simd_assign is true if simd_linear_assign() or simd_linear_assign(de1, de2) + // is true. linear_assigner::run(de1, de2); - } - else - { - linear_assigner::run(de1, de2); - } + } + else + { + linear_assigner::run(de1, de2); + } #pragma GCC diagnostic pop } else if (simd_strided_assign)