Skip to content

Support C++23 atomic shims#941

Open
bc-lee wants to merge 1 commit into
swiftlang:mainfrom
bc-lee:feature/cpp23-atomic-shims
Open

Support C++23 atomic shims#941
bc-lee wants to merge 1 commit into
swiftlang:mainfrom
bc-lee:feature/cpp23-atomic-shims

Conversation

@bc-lee
Copy link
Copy Markdown

@bc-lee bc-lee commented Apr 27, 2026

In C++23, libc++'s <stdatomic.h> exposes std::atomic-based APIs instead of the C atomic interfaces that libdispatch's shim expects. That makes the existing _Atomic storage incompatible with atomic_load_explicit(), atomic_fetch_*(), and related calls when libdispatch is compiled as C++.

Route libdispatch's internal atomic operations through private _dispatch_atomic_* aliases. Clang C++23 keeps _Atomic storage and uses __c11_atomic_* builtins directly. GCC C++23 uses plain storage with __atomic_* builtins so the shim does not depend on public <stdatomic.h> names in that mode. C and older C++ modes continue to use <stdatomic.h>.

Fixes #940.

In C++23, libc++'s <stdatomic.h> exposes std::atomic-based APIs
instead of the C atomic interfaces that libdispatch's shim expects.
That makes the existing _Atomic storage incompatible with
atomic_load_explicit(), atomic_fetch_*(), and related calls when
libdispatch is compiled as C++.

Route libdispatch's internal atomic operations through private
_dispatch_atomic_* aliases. Clang C++23 keeps _Atomic storage and uses
__c11_atomic_* builtins directly. GCC C++23 uses plain storage with
__atomic_* builtins so the shim does not depend on public <stdatomic.h>
names in that mode. C and older C++ modes continue to use <stdatomic.h>.
@compnerd
Copy link
Copy Markdown
Member

ibdispatch is a C library, not a C++ library, so I'm not sure I understand why this should be needed.

@bc-lee
Copy link
Copy Markdown
Author

bc-lee commented Apr 27, 2026

libdispatch is primarily a C library, but this repo does compile C++ code, including src/block.cpp. That file includes internal.h -> shims.h -> shims/atomic.h, so a C++23 <stdatomic.h> incompatibility is relevant if that translation unit is built in C++23 mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C++23 <stdatomic.h> is incompatible with libdispatch's _Atomic shim

2 participants