public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch][libstdc++] Add constexpr specifier to function
@ 2024-06-06  2:36 Deev Patel
  2024-06-06  6:49 ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: Deev Patel @ 2024-06-06  2:36 UTC (permalink / raw)
  To: gcc-patches, libstdc++

[-- Attachment #1: Type: text/plain, Size: 1873 bytes --]

Things like std::atomic<double> are currently unable to be created in a
constexpr context with clang 18 and c++20. Example compilation error
```
external/com_google_tcmalloc/tcmalloc/parameters.cc:223:17: error: variable
does not have a constant initializer
  223 |     Parameters::peak_sampling_heap_growth_fraction_(1.1);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/com_google_tcmalloc/tcmalloc/parameters.cc:222:1: note: required
by 'constinit' specifier here
  222 | ABSL_CONST_INIT std::atomic<double>
      | ^~~~~~~~~~~~~~~
external/com_google_absl/absl/base/attributes.h:743:25: note: expanded from
macro 'ABSL_CONST_INIT'
  743 | #define ABSL_CONST_INIT constinit
      |                         ^~~~~~~~~
external/local_config_clang/crosstool/extra_tools/lib/gcc/x86_64-linux-gnu/14.1.0/../../../../include/c++/14.1.0/bits/atomic_base.h:1286:9:
note: non-constexpr function '__clear_padding<double>' cannot be used in a
constant expression
 1286 |       { __atomic_impl::__clear_padding(_M_fp); }
      |         ^
external/local_config_clang/crosstool/extra_tools/lib/gcc/x86_64-linux-gnu/14.1.0/../../../../include/c++/14.1.0/atomic:1644:38:
note: in call to '__atomic_float(1.100000e+00)'
 1644 |       atomic(double __fp) noexcept : __atomic_float<double>(__fp)
```

This patch adds the necessary constexpr specifier.

- Deev Patel

diff --git a/libstdc++-v3/include/bits/atomic_base.h
b/libstdc++-v3/include/bits/atomic_base.h
index 062f1549740..5e89f66f620 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*
+      constexpr _GLIBCXX_ALWAYS_INLINE _Tp*
       __clear_padding(_Tp& __val) noexcept
       {
        auto* __ptr = std::__addressof(__val);

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-06-08 15:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-06  2:36 [Patch][libstdc++] Add constexpr specifier to function Deev Patel
2024-06-06  6:49 ` Jonathan Wakely
2024-06-06  6:51   ` Jonathan Wakely
2024-06-08 15:07     ` [committed v2][libstdc++] Add constexpr specifier to function __atomic_impl::__clear_padding Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).