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

--- Comment #22 from Hans-Peter Nilsson <hp at gcc dot gnu.org> ---
The issue again, is using properties of the actual object in the value of
is_lock_free().
AFAICS, that still happens (at r264855)

libstdc++-v3/include/bits/atomic_base.h:246
      static constexpr int _S_alignment =
        sizeof(_ITp) > alignof(_ITp) ? sizeof(_ITp) : alignof(_ITp);

      alignas(_S_alignment) __int_type _M_i;

libstdc++-v3/include/bits/atomic_base.h:353
      bool
      is_lock_free() const noexcept
      {
        // Use a fake, minimally aligned pointer.
        return __atomic_is_lock_free(sizeof(_M_i),
            reinterpret_cast<void *>(-__alignof(_M_i)));
      }

To me, is_lock_free doesn't seem to be constant over all objects of
the same type, when the expression to __atomic_is_lock_free is based
on the particular object; the fake-pointer (void*) -__alignof(_M_i).

Or do I misread that?  Are __alignof(x) and the result of alignas(x)
in the declaration guaranteed to always be the same here?  This seems
to be the crux.  (If so, can we add an assert somehow to make this
clearer?)

Anyway, as per the arguments in n2992.html in the link above, I (still) think
__atomic_*always*_lock free should be used instead; this'd make the intent
clear.

Reply via email to