Qt-Autosar-A18.5.11

“operator new” and “operator delete” shall be defined together

Required inputs: IR

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