abseil-cpp icon indicating copy to clipboard operation
abseil-cpp copied to clipboard

absl::btree_map: constexpr variable 'kFirst' must be initialized by a constant expression

Open thekiwicoder0 opened this issue 4 years ago • 3 comments

Hi I am receiving a compiler error use of aseil::btree_map running it through clang.

absl/container/internal/container_memory.h:259:27: error: constexpr variable 'kFirst' must be initialized by a constant expression [clang-diagnostic-error] static constexpr size_t kFirst = offsetof(Pair, first);

The offending code is: template <class Pair> struct OffsetOf<Pair, typename std::is_standard_layout<Pair>::type> { static constexpr size_t kFirst = offsetof(Pair, first); static constexpr size_t kSecond = offsetof(Pair, second); };

And seems to be caused by the use of 'offsetof', which makes use of reinterpret_cast: #define offsetof(s,m) ((::size_t)&reinterpret_cast<char const volatile&>((((s*)0)->m)))

Which is not allowed in a constexpr expression.

Any ideas how to fix this?

The abseil sdk is from 2020-04-01 And using llvm10

Thanks

thekiwicoder0 avatar Jul 01 '20 11:07 thekiwicoder0

What is the standard library are you using?

rogeeff avatar Jul 07 '20 15:07 rogeeff

C++17, looks like it's pulling that definition from here: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\stddef.h

thekiwicoder0 avatar Jul 07 '20 17:07 thekiwicoder0