https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126230
--- Comment #7 from Alexander Krabler <code at a dot krabler.eu> ---
(In reply to Tomasz KamiĆski from comment #5)
> The program in the example is not required to return zero, prior the
> implementation of the C++20 P0528: The Curious Case of Padding Bits,
> Featuring Atomic Compare-and-Exchange. ...
That's true, but that was not my point.
GCC>=13 expects a specific invariant to be fulfilled, that all padding bits of
atomics are cleared on storage, this invariant is ensured by store() etc. by
clearing padding bits before writing into the atomic.
But that invariant can easily be violated when some TUs are GCC<=12.
Following example should make that more clear, change main.cc to:
#include <atomic>
struct WithPadding {
char small;
short big;
};
void store_padding(std::atomic<WithPadding>&);
int main() {
std::atomic<WithPadding> atomic_padding;
store_padding(atomic_padding);
auto expected = atomic_padding.load();
while (!atomic_padding.compare_exchange_strong(expected, {})) {}
}
Now, this is guaranteed to terminate before P0528 with GCC12 (max. 2
iterations) and after it with GCC13 (max. 1 iteration).
However, it does never terminate with the store_paddicng.cc with GCC<=12 and
main.cc with GCC>=13,
which is the ABI break.