[Patch][libstdc++] Add constexpr specifier to function
Things like std::atomic 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 | ^~~ 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' 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.10e+00)' 1644 | atomic(double __fp) noexcept : __atomic_float(__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 - _GLIBCXX_ALWAYS_INLINE _Tp* + constexpr _GLIBCXX_ALWAYS_INLINE _Tp* __clear_padding(_Tp& __val) noexcept { auto* __ptr = std::__addressof(__val);
[PATCH] libstdc++: Add missing constexpr specifier and function overloads
Hi, A couple of virtual functions in the libstdc++ format header are marked constexpr in the base class, but not in the derived class. This was causing build failures when trying to compile latest gcc libstd with clang 16 using c++20. Adding the constexpr specifier resolves the issue. 2023-07-23 Deev Patel * include/std/format: Add missing constexpr specifiers on function overloads >From ac34afa1109b4c82e5cc377f49abf55422b89529 Mon Sep 17 00:00:00 2001 From: Deev Patel Date: Sun, 23 Jul 2023 20:08:46 -0700 Subject: [PATCH] [libstdc++] Add missing constexpr specifiers on function overloads --- libstdc++-v3/include/std/format | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format index 9710bff3c03..0c6069b2681 100644 --- a/libstdc++-v3/include/std/format +++ b/libstdc++-v3/include/std/format @@ -3554,14 +3554,14 @@ namespace __format using iterator = typename _Scanner<_CharT>::iterator; - void + constexpr void _M_on_chars(iterator __last) override { basic_string_view<_CharT> __str(this->begin(), __last); _M_fc.advance_to(__format::__write(_M_fc.out(), __str)); } - void + constexpr void _M_format_arg(size_t __id) override { using _Context = basic_format_context<_Out, _CharT>; -- 2.41.0