[Bug c++/70647] New: Feature request: warning for self-moving in constructors

matt at godbolt dot org gcc-bugzilla@gcc.gnu.org
Wed Apr 13 20:24:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70647

            Bug ID: 70647
           Summary: Feature request: warning for self-moving in
                    constructors
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: matt at godbolt dot org
  Target Milestone: ---

Consider the following code:

#include <utility> // for std::move
struct A {
  int a; int b;

  A(A &&o) 
    : a(a), // I get a warning here...
      b(o.b) {}  
};
struct B { 
  int a; int b; 
  B(B &&o) 
    : a(std::move(a)),  // but sadly not here
      b(std::move(o.b)) {}
};

[ c.f https://godbolt.org/g/v7zPYL ]

In the non-moving case, I get a warning that I've typoed and assigned a with
itself.

In the move case, there's no such warning. I appreciate this is probably
difficult (if not impossible) to detect, but if there's any way it can be done,
it would save a painful debugging session or two!


More information about the Gcc-bugs mailing list