Issue 76064
Summary [cppcoreguidelines-special-member-functions] Spiritually false positive for `operator=(T)`
Labels
Assignees
Reporter Eisenwave
    Consider the example (https://godbolt.org/z/fPP6cnbYv):
```cpp
struct MyClass {
    MyClass(const MyClass&);
    MyClass(MyClass&&);
 ~MyClass();
    MyClass& operator=(MyClass other) noexcept;
};
```
```none
<source>:1:8: warning: class 'MyClass' defines a destructor, a copy constructor, a copy assignment operator and a move constructor but does not define a move assignment operator [cppcoreguidelines-special-member-functions]
    1 | struct MyClass {
 |        ^
```
Technically, clang-tidy is right, and `MyClass` does not have a move assignment operator.

However, this is spiritually a false positive because `operator=(MyClass)` accepts both rvaues and lvalues and is acting as a "unified" assignment operator. clang-tidy should not emit a diagnostic in the event that the copy assignment operator has a by-value parameter, or this behavior should be configurable somehow.

See [Stack Overflow/clang-tidy does not recognize unifying assignment operator as move assigment](https://stackoverflow.com/q/77692186/5740428) for more discussion.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to