[llvm-bugs] [Bug 43124] New: clang++ gives false warnings about self-assign-overloaded expressions
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Aug 27 08:59:34 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=43124
Bug ID: 43124
Summary: clang++ gives false warnings about
self-assign-overloaded expressions
Product: clang
Version: 8.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: j.l.k at gmx.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
neeilans at live.com, richard-llvm at metafoo.co.uk
Clang 8.0.1 produces false warnings for expressions like `a -= a` and `a /= a`,
even when `a` is not a number and the overloaded operators don't do any
arithmetic operations, let alone when their return type is completely different
from `decltype(a)`.
Consider this code:
```
class Vector {
public:
Vector& operator+=(const Vector &v) { return *this; }
Vector& operator-=(const Vector &v) { return *this; }
Vector& operator*=(const Vector &v) { return *this; }
Vector& operator/=(const Vector &v) { return *this; }
};
int main()
{
Vector v;
v += v;
v -= v;
v *= v;
v /= v;
}
```
When compiled with clang++ 8.0.1, I get the following warnings:
```
$ clang++ -Wall example2.cpp -o example2
example2.cpp:13:7: warning: explicitly assigning value of variable of type
'Vector' to
itself [-Wself-assign-overloaded]
v -= v;
~ ^ ~
example2.cpp:15:7: warning: explicitly assigning value of variable of type
'Vector' to
itself [-Wself-assign-overloaded]
v /= v;
~ ^ ~
2 warnings generated.
```
See also https://stackoverflow.com/q/57645872 and
https://github.com/pybind/pybind11/issues/1893 for a real-world non-trivial and
non-arithmetic example of self-assignment expressions using overloaded
operators.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190827/09811a2b/attachment.html>
More information about the llvm-bugs
mailing list