Skip to content

[clang-tidy] Check request: detect suspicious deleted constructor and assignment operator #120923

@denzor200

Description

@denzor200

In C++20 mode it becomes possible to use auto in a function parameter declaration, so thus it's possible to write strange code like this:

struct A {
    A() = default;
    A(const auto& other) = delete;
    A& operator=(const auto& other) = delete;
};

These two deleted functions don't make sense indeed and they look suspicious - looks like someone tried to make A noncopyable.
The root of the problem is that A still remains copyable, which might be bugproned.
In my opinion it's easy to make such typo in the code, especially if you are following guideline that orders you to always use auto everywhere it's possible.
Suppose we need a check that will automatically provide the fix for the code above:

struct A {
    A() = default;
    A(const A& other) = delete;
    A& operator=(const A& other) = delete;
};

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions