<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/132998>132998</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
ABI break for `_Atomic` in C++23 when using libstdc++
</td>
</tr>
<tr>
<th>Labels</th>
<td>
ABI,
c++23,
libstdc++,
diverges-from:gcc
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zygoloid
</td>
</tr>
</table>
<pre>
In C++23 onwards, [`<stdatomic.h>` `#define`s `_Atomic(T)` as `std::atomic<T>`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p0943r6.html). This results in an ABI break when using libstdc++. Example:
```c++
#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](https://godbolt.org/z/Y9G7sYcsE) 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.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx0VE1v6yoQ_TVkM0rkDIkTL7zIR_PUfaWnu6owjG3usyECXLf99U_jWE17bytZMgwDc-acAypG2ziiUmyPYnteqCG1PpTvb43vvDWLypu38tHBSeBR4BEleDeqYKLAE_CePBPyFJNRyfdWr1ohH0SeAcdRGqqtI5FnkQPPhylH4P5JYMFZaorHZIQ8CHm4nSHk6el2itieBe7blK6RE_Ai8DKO48pfyS1jMisfGoGX30mvBV6iRuSEBnlmvI4CL1d1pcADzDDjeVZsZMhXbeo7gcUKnlobIVAcuhTBOlAODsdHqAKp_2BsycEQrWugs1VMRt9oWMHDq-qvHTGsbPry7PbNGRxCaZ3uBkPwN0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