public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/109396] New: Winit-self doesn't warn when std::move()-d @ 2023-04-03 22:00 barry.revzin at gmail dot com 2023-04-04 0:50 ` [Bug c++/109396] " pinskia at gcc dot gnu.org ` (4 more replies) 0 siblings, 5 replies; 6+ messages in thread From: barry.revzin at gmail dot com @ 2023-04-03 22:00 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109396 Bug ID: 109396 Summary: Winit-self doesn't warn when std::move()-d Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: barry.revzin at gmail dot com Target Milestone: --- In this example: #include <utility> struct A { int i_; A(int i) : i_(i_) { } }; struct B { int i_; B(int i) : i_(std::move(i_)) { } }; Compiling on gcc trunk with -Wall -Wextra gives me these warnings: <source>:6:5: warning: 'A::i_' is initialized with itself [-Winit-self] 6 | A(int i) : i_(i_) { } | ^ <source>:6:11: warning: unused parameter 'i' [-Wunused-parameter] 6 | A(int i) : i_(i_) { } | ~~~~^ <source>: In constructor 'B::B(int)': <source>:12:11: warning: unused parameter 'i' [-Wunused-parameter] 12 | B(int i) : i_(std::move(i_)) { } | ~~~~^ -Winit-self warns on the self-initialization of A::i_ but not of B::i_ (which is just as much a self-initialization, but via std::move). It would be nice if -Winit-self caught the std::move (or other explicit rvalue cast) case as well. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/109396] Winit-self doesn't warn when std::move()-d 2023-04-03 22:00 [Bug c++/109396] New: Winit-self doesn't warn when std::move()-d barry.revzin at gmail dot com @ 2023-04-04 0:50 ` pinskia at gcc dot gnu.org 2023-04-04 15:51 ` mpolacek at gcc dot gnu.org ` (3 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-04-04 0:50 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109396 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |enhancement ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/109396] Winit-self doesn't warn when std::move()-d 2023-04-03 22:00 [Bug c++/109396] New: Winit-self doesn't warn when std::move()-d barry.revzin at gmail dot com 2023-04-04 0:50 ` [Bug c++/109396] " pinskia at gcc dot gnu.org @ 2023-04-04 15:51 ` mpolacek at gcc dot gnu.org 2024-05-28 19:04 ` cvs-commit at gcc dot gnu.org ` (2 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: mpolacek at gcc dot gnu.org @ 2023-04-04 15:51 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109396 Marek Polacek <mpolacek at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 CC| |mpolacek at gcc dot gnu.org Status|UNCONFIRMED |ASSIGNED Last reconfirmed| |2023-04-04 Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org --- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> --- Confirmed. I would've thought that -Wself-move caught that but no. Likely mine for GCC 14. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/109396] Winit-self doesn't warn when std::move()-d 2023-04-03 22:00 [Bug c++/109396] New: Winit-self doesn't warn when std::move()-d barry.revzin at gmail dot com 2023-04-04 0:50 ` [Bug c++/109396] " pinskia at gcc dot gnu.org 2023-04-04 15:51 ` mpolacek at gcc dot gnu.org @ 2024-05-28 19:04 ` cvs-commit at gcc dot gnu.org 2024-05-28 19:11 ` mpolacek at gcc dot gnu.org 2024-05-28 19:12 ` sjames at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: cvs-commit at gcc dot gnu.org @ 2024-05-28 19:04 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109396 --- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>: https://gcc.gnu.org/g:efaaae49b307fcc7e771518da3edae49f92c19db commit r15-871-gefaaae49b307fcc7e771518da3edae49f92c19db Author: Marek Polacek <polacek@redhat.com> Date: Thu May 23 15:49:42 2024 -0400 c++: extend -Wself-move for mem-init-list [PR109396] We already warn for: x = std::move (x); which triggers: warning: moving 'x' of type 'int' to itself [-Wself-move] but bug 109396 reports that this doesn't work for a member-initializer-list: X() : x(std::move (x)) so this patch amends that. PR c++/109396 gcc/cp/ChangeLog: * cp-tree.h (maybe_warn_self_move): Declare. * init.cc (perform_member_init): Call maybe_warn_self_move. * typeck.cc (maybe_warn_self_move): No longer static. Change the return type to bool. Also warn when called from a member-initializer-list. Drop the inform call. gcc/testsuite/ChangeLog: * g++.dg/warn/Wself-move2.C: New test. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/109396] Winit-self doesn't warn when std::move()-d 2023-04-03 22:00 [Bug c++/109396] New: Winit-self doesn't warn when std::move()-d barry.revzin at gmail dot com ` (2 preceding siblings ...) 2024-05-28 19:04 ` cvs-commit at gcc dot gnu.org @ 2024-05-28 19:11 ` mpolacek at gcc dot gnu.org 2024-05-28 19:12 ` sjames at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: mpolacek at gcc dot gnu.org @ 2024-05-28 19:11 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109396 Marek Polacek <mpolacek at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |FIXED Status|ASSIGNED |RESOLVED --- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> --- Fixed. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/109396] Winit-self doesn't warn when std::move()-d 2023-04-03 22:00 [Bug c++/109396] New: Winit-self doesn't warn when std::move()-d barry.revzin at gmail dot com ` (3 preceding siblings ...) 2024-05-28 19:11 ` mpolacek at gcc dot gnu.org @ 2024-05-28 19:12 ` sjames at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: sjames at gcc dot gnu.org @ 2024-05-28 19:12 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109396 Sam James <sjames at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |15.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-05-28 19:12 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-04-03 22:00 [Bug c++/109396] New: Winit-self doesn't warn when std::move()-d barry.revzin at gmail dot com 2023-04-04 0:50 ` [Bug c++/109396] " pinskia at gcc dot gnu.org 2023-04-04 15:51 ` mpolacek at gcc dot gnu.org 2024-05-28 19:04 ` cvs-commit at gcc dot gnu.org 2024-05-28 19:11 ` mpolacek at gcc dot gnu.org 2024-05-28 19:12 ` sjames at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).