diff --git a/subsys/cpp/cpp_new.cpp b/subsys/cpp/cpp_new.cpp index 38c66a71370..4a2c0044602 100644 --- a/subsys/cpp/cpp_new.cpp +++ b/subsys/cpp/cpp_new.cpp @@ -5,6 +5,7 @@ */ #include +#include #if __cplusplus < 201103L #define NOEXCEPT @@ -32,6 +33,30 @@ void* operator new[](std::size_t size, const std::nothrow_t& tag) NOEXCEPT return malloc(size); } +#if __cplusplus >= 201703L +void* operator new(size_t size, std::align_val_t al) +{ + return aligned_alloc(static_cast(al), size); +} + +void* operator new[](std::size_t size, std::align_val_t al) +{ + return aligned_alloc(static_cast(al), size); +} + +void* operator new(std::size_t size, std::align_val_t al, + const std::nothrow_t&) NOEXCEPT +{ + return aligned_alloc(static_cast(al), size); +} + +void* operator new[](std::size_t size, std::align_val_t al, + const std::nothrow_t&) NOEXCEPT +{ + return aligned_alloc(static_cast(al), size); +} +#endif /* __cplusplus >= 201703L */ + void operator delete(void* ptr) NOEXCEPT { free(ptr); diff --git a/subsys/cpp/include/new b/subsys/cpp/include/new index 535727c9dcf..cbefcd50c41 100644 --- a/subsys/cpp/include/new +++ b/subsys/cpp/include/new @@ -24,6 +24,10 @@ namespace std { }; #endif /* __cplusplus */ extern const std::nothrow_t nothrow; -} +#if __cplusplus >= 201703L + enum class align_val_t : std::size_t {}; +#endif /* CONFIG_STD_CPP17 */ + +} #endif /* ZEPHYR_SUBSYS_CPP_INCLUDE_NEW_ */