Skip to content

[clang-tidy] Check request: detect incorrect creating of std::enable_shared_from_this objects #120853

@denzor200

Description

@denzor200
struct A : std::enable_shared_from_this {
};
std::shared_ptr<A> a2 = std::make_shared<A>(); // OK
std::shared_ptr<A> a1(new A); // OK
auto* a3 = new A; // INCORRECT
A a; // INCORRECT

These two incorrect usages might contain hidden termination (via SIGSEGV, or uncaught "bad_weak_ptr" exception).
Suppose it easily to detect by clang-tidy and might be really helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions