On Thu, 6 Jun 2024 at 07:49, Jonathan Wakely <jwak...@redhat.com> wrote:
>
> On Thu, 6 Jun 2024 at 03:37, Deev Patel <dkp10...@gmail.com> wrote:
> >
> > 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*
>
> Thanks. I'm pretty sure the constexpr should go after the
> always_inline attribute, but I'll take care of it.

And it might need to be _GLIBCXX14_CONSTEXPR because the function
isn't a valid constexpr function in C++11 mode (and doesn't need to
be, because atomic<floating-point-type> doesn't exist in C++11).

>
> >        __clear_padding(_Tp& __val) noexcept
> >        {
> >         auto* __ptr = std::__addressof(__val);

Reply via email to