Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
denzor200 opened this issue Dec 22, 2024 · 0 comments
Labels
check-request Request for a new check in clang-tidy clang-tidy

Comments

@denzor200
Copy link

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;
};
@EugeneZelenko EugeneZelenko added the check-request Request for a new check in clang-tidy label Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
check-request Request for a new check in clang-tidy clang-tidy
Projects
None yet
Development

No branches or pull requests

2 participants