Skip to content

aligned_alloc not supported by all standard libraries

In file alignedallocator.hh the C11 function aligned_alloc is called that is part of the c++ standard from C++17. Some compilers may provide this functionality in its standard library already, but others not. I've tested on different systems: on our cluster, the standard library does not know aligned_alloc neither in the C library stdlib.h nor using std=c++1z with g++-7. I think, the test #if __APPLE__ is too specific, to find all not working standard libraries.

Better: include a C++ feature test in CheckCXXFeatures.cmake for this function, e.g.

check_cxx_source_compiles("
  #include <cstdlib>
  int main()
  {
    int* p = static_cast<int*>(aligned_alloc(1024, 1024*sizeof *p));
    std::free(p);
  }
" DUNE_SUPPORTS_C_ALIGNED_ALLOC)

maybe in the future, add also a test for c++ standard library implementation of this function, i.e.

check_cxx_source_compiles("
  #include <cstdlib>
  int main()
  {
    int* p = static_cast<int*>(std::aligned_alloc(1024, 1024*sizeof *p));
    std::free(p);
  }
" DUNE_SUPPORTS_CXX_ALIGNED_ALLOC)