[Bug c++/70647] Feature request: warning for self-moving in constructors
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70647 --- Comment #4 from Matt Godbolt --- Agreed re: cast/FE. I couldn't quite get your example to fail as the "o" parameter is unusued (which would be a good clue! #include // for std::move struct B { int a; int b; B(B &) : a(b), b(o.a) {} }; passes just fine though; which is grist for the mill for bug 19808 being fixed (e.g. https://godbolt.org/g/QHLCQv ) Thanks again!
[Bug c++/70647] Feature request: warning for self-moving in constructors
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70647 --- Comment #3 from Manuel López-Ibáñez --- > --- Comment #2 from Matt Godbolt --- > Thanks Manuel. Interestingly this does elicit a warning: > > struct B { > int a; int b; > B(B &) > : a(static_cast(a)), > b(std::move(o.b)) {} > }; Most probable, the FE removes the cast before reaching this warning, so the warning does not see an expression. If you cast to something non trivial, it remains an expression and the warning doesn't try to look inside it. I wonder what happens if you do a(b), a(a). Does it still warn? My guess would be yes. If so, it is just checking for equality on both sides, no attempt to look within expressions nor track initialisation.
[Bug c++/70647] Feature request: warning for self-moving in constructors
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70647 --- Comment #2 from Matt Godbolt --- Thanks Manuel. Interestingly this does elicit a warning: struct B { int a; int b; B(B &) : a(static_cast(a)), b(std::move(o.b)) {} }; but this does not: struct B { int a; int b; B(B &) : a(static_cast(a)), b(std::move(o.b)) {} }; That said; I believe bug 19808 would indeed help in this situation!
[Bug c++/70647] Feature request: warning for self-moving in constructors
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70647 Manuel López-Ibáñez changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED CC||manu at gcc dot gnu.org Resolution|--- |DUPLICATE --- Comment #1 from Manuel López-Ibáñez --- (In reply to Matt Godbolt from comment #0) > 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! I don't think "move" has anything to do with this. If you use "a + 1" or "foo(a)", you are still initializing "a" with an uninitialized value. In that sense, this is what PR19808 is about, for which there is a patch but, sadly, nobody has had so far the time or interest to finish it and properly submit it. *** This bug has been marked as a duplicate of bug 19808 ***