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

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).