diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -693,16 +693,29 @@ #if EIGEN_MAX_CPP_VER>=11 && \ (__cplusplus >= 201103L || EIGEN_COMP_MSVC >= 1700) #define EIGEN_HAS_CXX11_OVERRIDE_FINAL 1 #else #define EIGEN_HAS_CXX11_OVERRIDE_FINAL 0 #endif #endif +#ifndef EIGEN_HAS_CXX17_OVERALIGN +#if EIGEN_MAX_CPP_VER>=17 && EIGEN_COMP_CXXVER>=17 && ( \ + (EIGEN_COMP_MSVC >= 1912) \ + || (EIGEN_GNUC_AT_LEAST(7,0)) \ + || ((!defined(__apple_build_version__)) && (EIGEN_COMP_CLANG>=500)) \ + || (( defined(__apple_build_version__)) && (__apple_build_version__>=10000000)) \ + ) +#define EIGEN_HAS_CXX17_OVERALIGN 1 +#else +#define EIGEN_HAS_CXX17_OVERALIGN 0 +#endif +#endif + #if defined(EIGEN_CUDACC) && EIGEN_HAS_CONSTEXPR // While available already with c++11, this is useful mostly starting with c++14 and relaxed constexpr rules #if defined(__NVCC__) // nvcc considers constexpr functions as __host__ __device__ with the option --expt-relaxed-constexpr #ifdef __CUDACC_RELAXED_CONSTEXPR__ #define EIGEN_CONSTEXPR_ARE_DEVICE_FUNC #endif #elif defined(__clang__) && defined(__CUDA__) && __has_feature(cxx_relaxed_constexpr) diff --git a/Eigen/src/Core/util/Memory.h b/Eigen/src/Core/util/Memory.h --- a/Eigen/src/Core/util/Memory.h +++ b/Eigen/src/Core/util/Memory.h @@ -784,16 +784,27 @@ template void swap(scoped_ar #endif /***************************************************************************** *** Implementation of EIGEN_MAKE_ALIGNED_OPERATOR_NEW [_IF] *** *****************************************************************************/ +#if EIGEN_HAS_CXX17_OVERALIGN + +// C++17 -> no need to bother about alignment anymore :) + +#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) +#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) +#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW +#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar,Size) + +#else + #if EIGEN_MAX_ALIGN_BYTES!=0 #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) \ void* operator new(std::size_t size, const std::nothrow_t&) EIGEN_NO_THROW { \ EIGEN_TRY { return Eigen::internal::conditional_aligned_malloc(size); } \ EIGEN_CATCH (...) { return 0; } \ } #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) \ void *operator new(std::size_t size) { \ @@ -826,16 +837,18 @@ template void swap(scoped_ar #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(true) #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar,Size) \ EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(bool( \ ((Size)!=Eigen::Dynamic) && \ (((EIGEN_MAX_ALIGN_BYTES>=16) && ((sizeof(Scalar)*(Size))%(EIGEN_MAX_ALIGN_BYTES )==0)) || \ ((EIGEN_MAX_ALIGN_BYTES>=32) && ((sizeof(Scalar)*(Size))%(EIGEN_MAX_ALIGN_BYTES/2)==0)) || \ ((EIGEN_MAX_ALIGN_BYTES>=64) && ((sizeof(Scalar)*(Size))%(EIGEN_MAX_ALIGN_BYTES/4)==0)) ))) +#endif + /****************************************************************************/ /** \class aligned_allocator * \ingroup Core_Module * * \brief STL compatible allocator to use with types requiring a non standrad alignment. * * The memory is aligned as for dynamically aligned matrix/array types such as MatrixXd. diff --git a/test/dynalloc.cpp b/test/dynalloc.cpp --- a/test/dynalloc.cpp +++ b/test/dynalloc.cpp @@ -102,17 +102,17 @@ template void check_custom_n } { std::size_t N = internal::random(1,10); T* t = new T[N]; delete[] t; } -#if EIGEN_MAX_ALIGN_BYTES>0 +#if EIGEN_MAX_ALIGN_BYTES>0 && (!EIGEN_HAS_CXX17_OVERALIGN) { T* t = static_cast((T::operator new)(sizeof(T))); (T::operator delete)(t, sizeof(T)); } { T* t = static_cast((T::operator new)(sizeof(T))); (T::operator delete)(t);