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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #3)
> I think that is because that transformation would violate the memory model
> of C++.

Ah yes. It would be safe for another thread to read the same memory location,
as long as they all read false so that no store to that location happens. If we
introduce a store, reads in other threads would conflict and we would have a
data race, i.e. undefined behaviour.

What the compiler doesn't know is that the standard already forbids any
potentially concurrent access, because _M_reset() is a non-const member
function.

So we can force the store to happen, as we know it's ok where the compiler
doesn't.

Reply via email to