]> granicus.if.org Git - clang/commit
[Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assign...
authorRoman Lebedev <lebedev.ri@gmail.com>
Sat, 7 Apr 2018 10:39:21 +0000 (10:39 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Sat, 7 Apr 2018 10:39:21 +0000 (10:39 +0000)
commit5b426516f5022f11076f185987bc019d31f99b79
treeb226aa3094bb1471484db367f7deccce41fcfb3b
parent5e1e76a1242d7387b3b75706f106f3de2bacd27a
[Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

Summary:
This has just bit me, so i though it would be nice to avoid that next time :)
Motivational case:
  https://godbolt.org/g/cq9UNk
Basically, it's likely to happen if you don't like shadowing issues,
and use `-Wshadow` and friends. And it won't be diagnosed by clang.

The reason is, these self-assign diagnostics only work for builtin assignment
operators. Which makes sense, one could have a very special operator=,
that does something unusual in case of self-assignment,
so it may make sense to not warn on that.

But while it may be intentional in some cases, it may be a bug in other cases,
so it would be really great to have some diagnostic about it...

Reviewers: aaron.ballman, rsmith, rtrieu, nikola, rjmccall, dblaikie

Reviewed By: rjmccall

Subscribers: EricWF, lebedev.ri, thakis, Quuxplusone, cfe-commits

Differential Revision: https://reviews.llvm.org/D44883

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329493 91177308-0d34-0410-b5e6-96231b3b80d8
docs/ReleaseNotes.rst
lib/Sema/SemaExpr.cpp
test/SemaCXX/member-init.cpp
test/SemaCXX/warn-self-assign-builtin.cpp [new file with mode: 0644]
test/SemaCXX/warn-self-assign-field-builtin.cpp [new file with mode: 0644]
test/SemaCXX/warn-self-assign-field-overloaded.cpp [new file with mode: 0644]
test/SemaCXX/warn-self-assign-overloaded.cpp [new file with mode: 0644]
test/SemaCXX/warn-self-assign.cpp [deleted file]