This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/70530] [DR2468] You should probably add addressof (a) != addressof (b) check to std::swap


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]