This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/70530] [DR2468] You should probably add addressof (a) != addressof (b) check to std::swap
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 27 Jan 2017 17:48:57 +0000
- Subject: [Bug libstdc++/70530] [DR2468] You should probably add addressof (a) != addressof (b) check to std::swap
- Auto-submitted: auto-generated
- References: <bug-70530-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70530
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Askar Safin from comment #5)
> 4. But (as it seems for me) the standard nowhere says that std::swap (a, a)
> is unspecified. So, it should be specified
It's specified to do:
T tmp = std::move(a);
a = std::move(a);
a = std::move(tmp);
Before DR2468 this whole thing had undefined behaviour, due to the "a =
std::move(a)" statement. Now that statement leaves 'a' in an unspecified state,
but then the next statement puts it back into a specified state. So there's no
undefined behaviour.
In your original comment you said "But there are other variants, of course. For
example, remove rvalue ref uniqueness assumption from the standard." And that's
what happened.
I still don't see any change needed to std::swap.