Skip to content

ABI break for _Atomic in C++23 when using libstdc++ #132998

Open
@zygoloid

Description

@zygoloid

In C++23 onwards, <stdatomic.h> #defines _Atomic(T) as std::atomic<T>. This results in an ABI break when using libstdc++. Example:

#include <stdatomic.h>
struct A { int m, n; char c; };
static_assert(sizeof(_Atomic(A)) == 16);

When using Clang with libstdc++, the built-in _Atomic(A) has size 16 but std::atomic<A> has size 12 on for example x86_64-linux-gnu. That means that including the <stdatomic.h> header in C++23, or switching from C++20 to C++23 when already including <stdatomic.h>, changes the ABI for the type that is spelled _Atomic(A).

In some sense this is the same issue as #26836, but we're now seeing different ABI behavior with two Clang builds depending on a -std= flag / a #include, which seems worse than before.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ABIApplication Binary Interfacec++23clangClang issues not falling into any other categorydiverges-from:gccDoes the clang frontend diverge from gcc on this issuelibstdc++GNU libstdc++ C++ standard library

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions