Skip to content
Snippets Groups Projects
Commit 2c5b0eee authored by Simon Praetorius's avatar Simon Praetorius
Browse files

Better test whether standard library supports aligned_alloc()

parent 99d1dc26
No related branches found
No related tags found
No related merge requests found
......@@ -484,6 +484,17 @@ check_cxx_source_compiles("
" DUNE_SUPPORTS_CXX_THROW_IN_CONSTEXPR
)
# Check whether the stadard library supports aligned_alloc()
check_cxx_source_compiles("
#include <cstdlib>
int main()
{
int* p = static_cast<int*>(aligned_alloc(64, 64*sizeof *p));
}
" DUNE_HAVE_C_ALIGNED_ALLOC
)
# ******************************************************************************
#
......
......@@ -35,6 +35,9 @@
/* does the compiler support conditionally throwing exceptions in constexpr context? */
#cmakedefine DUNE_SUPPORTS_CXX_THROW_IN_CONSTEXPR 1
/* does the standard library provides aligned_alloc()? */
#cmakedefine DUNE_HAVE_C_ALIGNED_ALLOC 1
/* does the standard library provide <experimental/type_traits> ? */
#cmakedefine DUNE_HAVE_HEADER_EXPERIMENTAL_TYPE_TRAITS 1
......
......@@ -6,6 +6,10 @@
#include "mallocallocator.hh"
#include <cstdlib>
#if !(DUNE_HAVE_C_ALIGNED_ALLOC || (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600))
#error Need either aligned_alloc() or posix_memalign() to compile AlignedAllocator
#endif
namespace Dune
{
......@@ -19,7 +23,7 @@ namespace Dune
template<class T, int Alignment = -1>
class AlignedAllocator : public MallocAllocator<T> {
#if __APPLE__
#if !DUNE_HAVE_C_ALIGNED_ALLOC
/*
* posix_memalign() on macOS has pretty draconian restrictions on the
......@@ -67,7 +71,7 @@ namespace Dune
if (n > this->max_size())
throw std::bad_alloc();
#if __APPLE__
#if !DUNE_HAVE_C_ALIGNED_ALLOC
/*
* Apple's standard library doesn't have aligned_alloc() - C11 is still something
* from the future in Cupertino. Luckily, they got around to finally implementing
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment