Issue 131220
Summary [clang-tidy] Check request: Avoid assigning `std::bind` capturing `this` to a field in a default-copyable class.
Labels clang-tidy
Assignees
Reporter denzor200
    
Needs a check that will do all the same as https://github.com/llvm/llvm-project/issues/120863, but will catch `std::bind` instead of C++11 lambda.

```
struct A {
   std::string content;
   std::function<void()> captured;

   A() {
    captured = std::bind(&A::perform, this); // INCORRECT
   }

   void perform() { std::cout << content << std::endl; }
};
```

```
struct A {
 std::string content;
   std::function<void()> captured;

   A() {
 captured = std::bind(&A::perform, this); // OK, see copy methods deleted below
   }
   
   A(const A&) = delete;
   A& operator=(const A&) = delete;

   void perform() { std::cout << content << std::endl; }
};
```

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to