AUTOSAR C++14 Rule A18-5-11
Description
Rule Definition
"operator new" and "operator delete" shall be defined together.
Rationale
You typically overload operator new
to perform some bookkeeping in
addition to allocating memory on the free store. Unless you overload the corresponding
operator delete
, it is likely that you omitted some corresponding
bookkeeping when deallocating the memory.
The defect can also indicate a coding error. For instance, you overloaded the placement
form of operator
new[]
:
void *operator new[](std::size_t count, void *ptr);
operator
delete[]
:void operator delete[](void *ptr);
void operator delete[](void *ptr, void *p );
When overloading operator new
, make sure that you overload the
corresponding operator delete
in the same scope, and vice versa. To find
the operator delete
corresponding to an operator new
,
see the reference pages for operator
new
and operator delete
.
Polyspace Implementation
The rule checker raises a violation when you overload operator new
but do not overload the corresponding operator delete
, or vice
versa.
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, Automated |