MISRA C++:2023 Rule 21.6.3
Description
Rule Definition
Advanced memory management shall not be used 1
Rationale
Using advanced memory management relies on properly handling complex issues such as
object lifetimes and use of std::launder
. These complexities can result
in difficult issues that are hard to identify and result in undefined behavior.
Examples of advanced memory management functions include:
All overloads of
operator new
andoperator delete
except for these overloads and their array counterparts:void * operator new (std::size_t count);
void * operator new (std::size_t count, const std::nothrow_t & tag);
void operator delete (void * ptr) noexcept;
void operator delete (void * ptr, std::size_t sz) noexcept;
void operator delete (void * ptr, const std::nothrow_t & tag) noexcept;
Use of
std::launder
Functions provided by the header file
<memory>
including:destroy()
,destroy_at()
, anddestroy_n()
uninitialized_copy()
anduninitialized_copy_n()
uninitialized_move()
anduninitialized_move_n()
uninitialized_fill()
anduninitialized_fill_n()
uninitialized_default_construct()
anduninitialized_default_construct_n()
uninitialized_value_construct()
anduninitialized_value_construct_n()
For a full list of advanced memory management functions and exceptions, see the MISRA™ C++:2023 documentation.
Uses of advanced memory management include:
Calling an advanced memory management function directly or by using a
new
expression or adelete
expressionTaking the address of an advanced memory management function
Explicitly calling a destructor
Declaring an
operator new
oroperator delete
function
Polyspace Implementation
Polyspace® reports violations on:
Declarations or uses of any advanced memory management function
Overloads of
operator new
andoperator delete
(not including exceptions described in the Rationale section)Explicitly calling a destructor or explicitly declaring an
operator new
oroperator delete
function
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Language support library |
Category: Required |
Version History
Introduced in R2024b
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.