diff mbox series

[committed,v2,libstdc++] Add constexpr specifier to function __atomic_impl::__clear_padding

Message ID 20240608150818.457672-1-jwakely@redhat.com
State New
Headers show
Series [committed,v2,libstdc++] Add constexpr specifier to function __atomic_impl::__clear_padding | expand

Commit Message

Jonathan Wakely June 8, 2024, 3:07 p.m. UTC
Here's what I pushed to trunk, using the macro instead of the plain
keyword, and with a testcase.

Thanks for the patch, Deev.

Tested x86_64-linux. Pushed to trunk. I'll backport this too.

-- >8 --

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>
---
 libstdc++-v3/include/bits/atomic_base.h                     | 2 +-
 libstdc++-v3/testsuite/29_atomics/atomic_float/constinit.cc | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic_float/constinit.cc
diff mbox series

Patch

diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index 062f1549740..20901b7fc06 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -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);
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_float/constinit.cc b/libstdc++-v3/testsuite/29_atomics/atomic_float/constinit.cc
new file mode 100644
index 00000000000..6b3f4f76b4c
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_float/constinit.cc
@@ -0,0 +1,3 @@ 
+// { dg-do compile { target c++20 } }
+#include <atomic>
+constinit std::atomic<float> a(0.0f);