Skip to content

[clang-tidy] Check request: readability-unnecessary-unique-release #145981

@denzor200

Description

@denzor200

std::shared_ptr's constructor has a lot of overloads, one of them has unique_ptr parameter.
People don't know about existense of that overload.
I've seen the code like this all over the place:

std::shared_ptr<Foo> process(std::unique_ptr<Foo> foo) {
   // ...
   return std::shared_ptr<Foo>(foo.release());
}

Need a check that will find such patterns and will change it to use constructor's overload with unique_ptr parameter:

std::shared_ptr<Foo> process(std::unique_ptr<Foo> foo) {
   // ...
   return std::shared_ptr<Foo>(std::move(foo));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions