https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123875
--- Comment #1 from Tomasz KamiĆski <tkaminsk at gcc dot gnu.org> ---
The workaround that we could use is to clear padding bits only for runtime (add
if (!_builtin_is_constant_evaluated()) check).
For the all objects of static or thread storage duration, zero-initialization
will already clear padding bits, so the __clear_padding call is not required.
This leaves us only with following example to consider:
```
void foo()
{
constexpr std::atomic<X> a(X{1, 2});
}
``
The padding bit here cannot be observed via atomic (API) they are return the by
value (thus have different set of padding bits). `compare_exchange_strong` is
mutating operations, so cannot be used.
We are left with code that will bitcast or memcpy object representation of a,
however, the standard does not guarantee that:
* std::atomic<X> a contains object of type X at all, so the bit-cast effect are
not specified
* require that padding bits inside atomic<X> are cleared, even if it contains
object of type X
* atomic<X> is trivially copyable (it is currently, but that is libstdc++ bug)