GeneralPurpose-DeleteIncompleteClass

Pointers to incomplete class types shall not be deleted

Required inputs: IR

Deleting a pointer to an incomplete class type results in undefined behavior because the compiler has no knowledge of the class size, alignment, or destructor. When a class is forward-declared but not defined, the delete operator cannot properly clean up before deallocating memory, leading to memory leaks, crashes, or heap corruption. Always ensure the complete type is visible at the point of deletion.
Bad code (incomplete type at deletion):
// forward.h
class Widget;  // Incomplete type - only declaration

// code.cpp
#include "forward.h"

void Process() {
    Widget* w = Create();           // Assuming Create() returns Widget*
    delete w;                        // ERROR: incomplete type at delete
}                                    // Undefined behavior!
Good code (complete type at deletion):
// widget.h
class Widget {                      // Complete type definition
public:
    Widget();
    ~Widget();
};

// code.cpp
#include "widget.h"

void Process() {
    Widget* w = new Widget();
    delete w;                        // OK: complete type, destructor called correctly
}
Good code (using smart pointers with complete type):
// forward.h
class Widget;  // Incomplete type

// code.cpp
#include "widget.h"  // Complete type definition

void Process() {
    std::unique_ptr<Widget> w(new Widget());  // OK: destructor generated at template instantiation
    // Automatic cleanup on scope exit
}

Possible Messages

Key

Text

Severity

Disabled

cafe_message

{}

None

False

Options

message_predicate

message_predicate : typing.Callable[[Cafe_Message], bool] | None = None

If provided, a custom predicate to filter relevant messages. Receives the message node and should return True for messages to report.
 

reported_severities

reported_severities : set[str] = {'error', 'remark', 'warning'}

List of severities to display.
 

use_error_number

use_error_number : bool = False

Whether the error number from the frontend should be used.
 

use_rule_severity

use_rule_severity : bool = False

Whether the rule's severity or the compiler's severity should be used.