zephyr/subsys/cpp/include/new
Piotr Pryga a0dc682bd9 cpp: new: Add no-throwing implementation of new operator
C++ subsystem defines exception throwing operator new.
Though the implementation never throws an exception.

If used by an application it should verify if requested
memory was allocated. This is against C++ standard.
If an application does not support exceptions or does not
want to call throwing new operator, it should use a
specialization of a new operator that makes sure it
never throws bad_alloc exception. The cpp subsystem
does not provide this specialization.

The commit adds missing operator new specializations.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-10-03 10:13:25 +02:00

30 lines
514 B
Plaintext

/*
* Copyright 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
*
* @brief Stub header allowing compilation of `#include <new>`
*/
#ifndef ZEPHYR_SUBSYS_CPP_INCLUDE_NEW_
#define ZEPHYR_SUBSYS_CPP_INCLUDE_NEW_
#include <cstddef>
namespace std {
#if __cplusplus < 201103L
struct nothrow_t {};
#else
struct nothrow_t {
explicit nothrow_t() = default;
};
#endif /* __cplusplus */
extern const std::nothrow_t nothrow;
}
#endif /* ZEPHYR_SUBSYS_CPP_INCLUDE_NEW_ */