Skip to main content
ai-slop/cpp-manual-deletemanual fix

Manual delete.

A raw `delete` or `delete[]` on a pointer. Ownership is manual, so an early return or exception between `new` and `delete` leaks, and a second `delete` is undefined behaviour.

Flagged shape and clean shape.

Each example shows the exact code shape the rule is looking for, then the smallest version that keeps the intent without hiding risk or adding noise.

cpp-manual-delete.cpp
✗ Flagged
void process(const Request& request) {
    Parser* parser = new Parser(request.body());
    if (!parser->valid()) {
        return;  // leaks parser
    }
    handle(parser->result());
    delete parser;
}
Why this trips

Deterministic line match on masked source: flags `delete` or `delete[]` followed by an expression, in C and C++ files.

cpp-manual-delete.cpp
✓ Clean
void process(const Request& request) {
    auto parser = std::make_unique<Parser>(request.body());
    if (!parser->valid()) {
        return;
    }
    handle(parser->result());
}
What changed

Own the resource with `std::unique_ptr` (via `std::make_unique`) or a container such as `std::vector`, so it is released automatically.

Agents mirror the `new`/`delete` pairs common in older C++ samples instead of using modern ownership types.

How this rule is justified.

Rule id

ai-slop/cpp-manual-delete

Enforcing engine

ai-slop

Detector strategy

Deterministic line match on masked source: flags `delete` or `delete[]` followed by an expression, in C and C++ files.

Legitimate code that is NOT flagged

Deleted functions (`= delete;`) and memory owned through `std::unique_ptr`, `std::shared_ptr`, or standard containers are not flagged.

Evidence

Part of aislop's C/C++ rule set. C/C++ support, including C/C++-specific AI-slop rules, arrived in aislop v0.14.1.