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

Ulrich Weigand <uweigand at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |uweigand at gcc dot gnu.org

--- Comment #1 from Ulrich Weigand <uweigand at gcc dot gnu.org> ---
Indeed, when running a simple test program:

#include <atomic>
#include <stdio.h>

struct twoints {
  int a;
  int b;
};

int main(void) {
   printf("%d\n", __alignof__ (twoints));
   printf("%d\n", __alignof__ (std::atomic<twoints>));
   return 0;
}

we see that the GCC only requires 4 bytes of alignment for the atomic type.

However, with the equivalent C11 code using the _Atomic keyword

#include <stdatomic.h>
#include <stdio.h>

struct twoints {
  int a;
  int b;
};

int main() {
   printf("%d\n", __alignof__ (struct twoints));
   printf("%d\n", __alignof__ (_Atomic (struct twoints)));
   return 0;
}

we get an alignment requirement of 8 bytes for the atomic type.

In the C case, this is done by the compiler front-end where it implements the
_Atomic keyword.  In the C++ case, it seems the compiler doesn't really get
involved, as it's all done in plain C++ in standard library code ...

I suspect the intent was that for C++, we likewise ought to have an increased
alignment requirement for the type, but I'm not sure how to implement this in
the library.  Need some of the library experts to comment here.

Reply via email to