Skip to content

[clang-tidy] "modernize-use-auto" - shared pointer specific casts not supported #134559

Open
@denzor200

Description

@denzor200

As the doc says, the check handles static_cast, dynamic_cast, const_cast, reinterpret_cast, functional casts, C-style casts and function templates that behave as casts, such as llvm::dyn_cast, boost::lexical_cast and gsl::narrow_cast. Calls to function templates are considered to behave as casts if the first template argument is explicit and is a type, and the function returns that type, or a pointer or reference to it.

Nothing written about std::static_pointer_cast, std::dynamic_pointer_cast, std::const_pointer_cast, std::reinterpret_pointer_cast, so I suggest to add support of all of them and their boost analogues.

Below is the sample how do I see such transformation.

BEFORE:

std::shared_ptr<const Derived> d = std::dynamic_pointer_cast<const Derived>(get_base());
std::shared_ptr<Derived> dm = std::const_pointer_cast<Derived>(d);

AFTER:

auto d = std::dynamic_pointer_cast<const Derived>(get_base());
auto dm = std::const_pointer_cast<Derived>(d);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions