xtensor: Fix darwin build with clang (#393992)

Co-authored-by: Petr Hodina <petr.hodina@luxonis.com>
This commit is contained in:
Aleksana
2025-03-30 12:01:27 +08:00
committed by GitHub
2 changed files with 69 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
From 475bedb15252a3732683f3a62c45cc3f1abbab5c Mon Sep 17 00:00:00 2001
From: Mykola Vankovych <mykola.vankovych@biodataanalysis.de>
Date: Tue, 14 Jan 2025 16:48:47 +0100
Subject: [PATCH] Added fixes for building with clang 19 (more strict template
matching rules)
---
include/xtensor/xexpression_traits.hpp | 7 +++----
include/xtensor/xstorage.hpp | 4 ++--
include/xtensor/xutils.hpp | 3 ++-
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/include/xtensor/xexpression_traits.hpp b/include/xtensor/xexpression_traits.hpp
index 205de67a5..2f84ae234 100644
--- a/include/xtensor/xexpression_traits.hpp
+++ b/include/xtensor/xexpression_traits.hpp
@@ -103,16 +103,15 @@ namespace xt
using type = xarray<T, L>;
};
-#if defined(__GNUC__) && (__GNUC__ > 6)
-#if __cplusplus == 201703L
+// Workaround for rebind_container problems when C++17 feature is enabled
+#ifdef __cpp_template_template_args
template <template <class, std::size_t, class, bool> class S, class X, std::size_t N, class A, bool Init>
struct xtype_for_shape<S<X, N, A, Init>>
{
template <class T, layout_type L>
using type = xarray<T, L>;
};
-#endif // __cplusplus == 201703L
-#endif // __GNUC__ && (__GNUC__ > 6)
+#endif // __cpp_template_template_args
template <template <class, std::size_t> class S, class X, std::size_t N>
struct xtype_for_shape<S<X, N>>
diff --git a/include/xtensor/xstorage.hpp b/include/xtensor/xstorage.hpp
index ac179a852..fec8e10f3 100644
--- a/include/xtensor/xstorage.hpp
+++ b/include/xtensor/xstorage.hpp
@@ -1637,8 +1637,8 @@ namespace xt
return !(lhs < rhs);
}
-// Workaround for rebind_container problems on GCC 8 with C++17 enabled
-#if defined(__GNUC__) && __GNUC__ > 6 && !defined(__clang__) && __cplusplus >= 201703L
+// Workaround for rebind_container problems when C++17 feature is enabled
+#ifdef __cpp_template_template_args
template <class X, class T, std::size_t N>
struct rebind_container<X, aligned_array<T, N>>
{
diff --git a/include/xtensor/xutils.hpp b/include/xtensor/xutils.hpp
index 9844b0ba7..b8c818efd 100644
--- a/include/xtensor/xutils.hpp
+++ b/include/xtensor/xutils.hpp
@@ -1023,7 +1023,8 @@ namespace xt
using type = C<X, allocator>;
};
-#if defined(__GNUC__) && __GNUC__ > 6 && !defined(__clang__) && __cplusplus >= 201703L
+// Workaround for rebind_container problems when C++17 feature is enabled
+#ifdef __cpp_template_template_args
template <class X, class T, std::size_t N>
struct rebind_container<X, std::array<T, N>>
{

View File

@@ -22,6 +22,9 @@ stdenv.mkDerivation (finalAttrs: {
hash = "sha256-hVfdtYcJ6mzqj0AUu6QF9aVKQGYKd45RngY6UN3yOH4=";
};
# See https://github.com/xtensor-stack/xtensor/pull/2821
patches = lib.optionals stdenv.cc.isClang [ ./0001-Fix-clang-build-errors-on-darwin.patch ];
nativeBuildInputs = [
cmake
];