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

            Bug ID: 117475
           Summary: C++20: Union object with atomic integer cannot be
                    statically initialized
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sebastian.hu...@embedded-brains.de
  Target Milestone: ---

The following test program fails to compile with GCC and -std=c++20:

#include <atomic>

typedef std::atomic_int Atomic_Int;

struct S {
  Atomic_Int v;
};

union U {
  S s;
};

U obj;

For example:

aarch64-rtems6-gcc -Wall -Wextra -std=c++20 -pedantic -S test.cc
test.cc:13:3: error: use of deleted function 'U::U()'
   13 | U obj;
      |   ^~~
test.cc:9:7: note: 'U::U()' is implicitly deleted because the default
definition would be ill-formed:
    9 | union U {
      |       ^
test.cc:10:5: error: union member 'U::s' with non-trivial 'constexpr S::S()'
   10 |   S s;
      |     ^

It works with clang 17.0.6:

clang -Wall -Wextra -std=c++20 -pedantic -S test.cc -o -
        .text
        .file   "test.cc"
        .type   obj,@object                     # @obj
        .bss
        .globl  obj
        .p2align        2, 0x0
obj:
        .zero   4
        .size   obj, 4

        .section        ".linker-options","e",@llvm_linker_options
        .ident  "clang version 17.0.6"
        .section        ".note.GNU-stack","",@progbits
        .addrsig

Reply via email to