diff options
author | Marek Polacek <polacek@redhat.com> | 2022-08-08 17:45:28 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2022-08-26 12:56:34 -0400 |
commit | 0abb78dda084a14b3d955757c6431fff71c263f3 (patch) | |
tree | e50c14d175e4d5e2e61ea340f47f00f92cf039a6 /gcc/c-family/c.opt | |
parent | 1e2462890ac748a5e5b6a34fdeb61e7027863a90 (diff) | |
download | gcc-0abb78dda084a14b3d955757c6431fff71c263f3.zip gcc-0abb78dda084a14b3d955757c6431fff71c263f3.tar.gz gcc-0abb78dda084a14b3d955757c6431fff71c263f3.tar.bz2 |
c++: Implement -Wself-move warning [PR81159]
About 5 years ago we got a request to implement -Wself-move, which
warns about useless moves like this:
int x;
x = std::move (x);
This patch implements that warning.
PR c++/81159
gcc/c-family/ChangeLog:
* c.opt (Wself-move): New option.
gcc/cp/ChangeLog:
* typeck.cc (maybe_warn_self_move): New.
(cp_build_modify_expr): Call maybe_warn_self_move.
gcc/ChangeLog:
* doc/invoke.texi: Document -Wself-move.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wself-move1.C: New test.
Diffstat (limited to 'gcc/c-family/c.opt')
-rw-r--r-- | gcc/c-family/c.opt | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index dfdebd5..f776efd 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -1229,6 +1229,10 @@ Wselector ObjC ObjC++ Var(warn_selector) Warning Warn if a selector has multiple methods. +Wself-move +C++ ObjC++ Var(warn_self_move) Warning LangEnabledBy(C++ ObjC++, Wall) +Warn when a value is moved to itself with std::move. + Wsequence-point C ObjC C++ ObjC++ Var(warn_sequence_point) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall) Warn about possible violations of sequence point rules. |