Check that aligned_alloc is available with cmake
Some compilers support C++17 even on targets that lack required functions. Projects that want to force C++17 will then run into a problem with std::aligned_alloc not existing on those targets, so it needs to be explicitly checked for. The alternative is to simply never use it even when it would be available.
This commit is contained in:
+2
-2
@@ -17,7 +17,7 @@ void *al_malloc(size_t alignment, size_t size)
|
||||
assert((alignment & (alignment-1)) == 0);
|
||||
alignment = std::max(alignment, alignof(std::max_align_t));
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
#if defined(HAVE_STD_ALIGNED_ALLOC)
|
||||
size = (size+(alignment-1))&~(alignment-1);
|
||||
return std::aligned_alloc(alignment, size);
|
||||
#elif defined(HAVE_POSIX_MEMALIGN)
|
||||
@@ -48,7 +48,7 @@ void *al_calloc(size_t alignment, size_t size)
|
||||
|
||||
void al_free(void *ptr) noexcept
|
||||
{
|
||||
#if (__cplusplus >= 201703L) || defined(HAVE_POSIX_MEMALIGN)
|
||||
#if defined(HAVE_STD_ALIGNED_ALLOC) || defined(HAVE_POSIX_MEMALIGN)
|
||||
std::free(ptr);
|
||||
#elif defined(HAVE__ALIGNED_MALLOC)
|
||||
_aligned_free(ptr);
|
||||
|
||||
Reference in New Issue
Block a user