Skip to content

Build failure against libstdc++ 14.2 with -std=c++20 #283

@nickdesaulniers

Description

@nickdesaulniers

Building against libstdc++14.2 fails:

external/tcmalloc+/tcmalloc/parameters.cc:253:17: error: variable does not have a constant initializer
  253 |     Parameters::per_cpu_caches_dynamic_slab_shrink_threshold_(0.4);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/tcmalloc+/tcmalloc/parameters.cc:252:1: note: required by 'constinit' specifier here
  252 | ABSL_CONST_INIT std::atomic<double>
      | ^~~~~~~~~~~~~~~
external/abseil-cpp+/absl/base/attributes.h:755:25: note: expanded from macro 'ABSL_CONST_INIT'
  755 | #define ABSL_CONST_INIT constinit
      |                         ^~~~~~~~~
[redacted]/14.2.0/include/c++/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); }
      |         ^
[redacted]/14.2.0/../../../gcc/x86_64-conda-linux-gnu/14.2.0/include/c++/atomic:1644:38: note: in call to '__atomic_float(4.000000e-01)'
 1644 |       atomic(double __fp) noexcept : __atomic_float<double>(__fp)
      |                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/tcmalloc+/tcmalloc/parameters.cc:253:17: note: in call to 'atomic(4.000000e-01)'
  253 |     Parameters::per_cpu_caches_dynamic_slab_shrink_threshold_(0.4);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[redacted]/14.2.0/include/c++/bits/atomic_base.h:972:7: note: declared here
  972 |       __clear_padding(_Tp& __val) noexcept
      |       ^

FWICT, I think libstdc++ had a bug in their 14.2 release where their std::atomic maybe wasn't constinit. This appears fixed in their 14.3 release (hence me not searching their issue tracker for a reference).

https://godbolt.org/z/b1bxeGzcY

I don't know if I'd call this a bug in abseil's ABSL_CONST_INIT; it's moreso a (now fixed) bug in libstdc++.

Maybe the answer is just "move to newer libstdc++ (there is 14.3, and 15.1) or libc++." But figured I'd file this in case compatibility with 14.2 is important.

One way to work around this, if libstdc++ exposes version info via preprocessor define, is to wrap ABSL_CONST_INIT when using it on std::atomic, I think, or simply omit ABSL_CONST_INIT. 🤷

Also, we're building with -std=gnu++20, hence ABSL_CONST_INIT expanding to constinit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions