libstdc++: Add missing constexpr to __atomic_impl::__clear_padding

This is called from the std::atomic<floating-point-type> constructor,
which needs to be usable in constant expressions.

libstdc++-v3/ChangeLog:

	* include/bits/atomic_base.h (__atomic_impl::__clear_padding):
	Add missing constexpr specifier.
	* testsuite/29_atomics/atomic_float/constinit.cc: New test.

Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
This commit is contained in:
Deev Patel 2024-06-06 11:53:25 +01:00 committed by Jonathan Wakely
parent 0bb1db32cc
commit ae91b5dd14
No known key found for this signature in database
2 changed files with 4 additions and 1 deletions

View File

@ -968,7 +968,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _Tp>
_GLIBCXX_ALWAYS_INLINE _Tp*
_GLIBCXX_ALWAYS_INLINE _GLIBCXX14_CONSTEXPR _Tp*
__clear_padding(_Tp& __val) noexcept
{
auto* __ptr = std::__addressof(__val);

View File

@ -0,0 +1,3 @@
// { dg-do compile { target c++20 } }
#include <atomic>
constinit std::atomic<float> a(0.0f);