Skip to content

[clang-tidy] Performance checks that detect redundant copies are flagging shared-state types #153247

@oracle-9

Description

@oracle-9

Currently, the checks performance-unnecessary-copy-initialization and performance-unnecessary-value-param are also triggered when shared-state objects (such as shared_future, shared_ptr, stop_source, stop_token, and weak_ptr) are passed or copied by value, recommending to pass them by reference instead.

However, passing these types by value is generally necessary to share ownership. Using references instead risks dangling lifetimes, such as when the callee outlives the caller or when all other owners are destroyed except the one holding a mistaken reference.

Consequently, (at least) the aforementioned types should be added to performance-unnecessary-copy-initialization.AllowedTypes and performance-unnecessary-value-param.AllowedTypes by default.

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