Skip to main content

IAR Embedded Workbench for RX 5.20

CPU-delete-throw (C++ only)

In this section:
Synopsis

An exception is thrown, or might be thrown, in an overloaded delete or delete[] operator.

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

An exception is thrown, or might be thrown, in an overloaded delete or delete[] operator. Because memory is often deallocated in a destructor, an exception that is thrown in a delete or delete[] operator is likely to be thrown during stack unwinding, which will cause the application to crash.

Coding standards
CERT ERR38-CPP

Deallocation functions must not throw exceptions

Code examples

The following code example fails the check and will give a warning:

class E{};

class C {
  void operator delete[ ](void* p) {
    if (!p){
      throw E();  //may throw an exception here
    }
  }
  int* p;
};

The following code example passes the check and will not give a warning about this issue:

void do_something();

class C {
  void operator delete[ ](void* p) {  //OK
    if (!p){
      do_something();
    }
  }
  int* p;
};