Qt-Autosar-A18.5.11¶
“operator new” and “operator delete” shall be defined together
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
Providing a custom allocation function (operator new) for a class or program implies the use of a custom memory management scheme different to the default one. It is therefore unlikely that memory allocated using a custom allocation function can be deallocated by the default deallocation function (operator delete).
Example
//% $Id: A18-5-11.cpp 316977 2018-04-20 12:37:31Z christof.meerwald $
#include <cstdlib>
class A {
public:
static void * operator new(std::size_t s); // Compliant: operator new
static void operator delete(void *ptr); // defined together with
// operator delete
};
class B {
public:
static void * operator new(std::size_t s); // Non-compliant: operator
static void * operator new [](std::size_t s); // new defined without
// corresponding operator
// delete
};
See Also
- HIC++ v4.0 [9]: 12.3.1: Correctly declare overloads for operator new and delete
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
array_delete_missing |
Scope contains operator new[] but not operator delete[] |
None |
False |
array_mixed_visibility |
Scope contains both new[] and delete[] operators but the visibility differs |
None |
False |
array_new_missing |
Scope contains operator delete[] but not operator new[] |
None |
False |
delete_missing |
Scope contains operator new but not operator delete |
None |
False |
mixed_visibility |
Scope contains both new and delete operators but visibility differs |
None |
False |
new_missing |
Scope contains operator delete but not operator new |
None |
False |
Options
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
This rule has no individual options.