You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All is in the title: I tried to compile protobuf 3.15.0 with gcc trunk and -std=gnu++20, and it fails with this error:
google/protobuf/unittest_lite.pb.cc:155:86: error: 'constinit' variable 'protobuf_unittest::_TestAllTypesLite_default_instance_' does not have a constant initializer
155 | PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestAllTypesLiteDefaultTypeInternal _TestAllTypesLite_default_instance_;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ./google/protobuf/unittest_lite.pb.h:25,
from google/protobuf/unittest_lite.pb.cc:4:
google/protobuf/unittest_lite.pb.cc:155:86: in 'constexpr' expansion of 'protobuf_unittest::TestAllTypesLiteDefaultTypeInternal()'
google/protobuf/unittest_lite.pb.cc:149:7: in 'constexpr' expansion of '((protobuf_unittest::TestAllTypesLiteDefaultTypeInternal*)this)->protobuf_unittest::TestAllTypesLiteDefaultTypeInternal::<anonymous>.protobuf_unittest::TestAllTypesLiteDefaultTypeInternal::<unnamed union>::_instance.protobuf_unittest::TestAllTypesLite::TestAllTypesLite((google::protobuf::internal::ConstantInitialized(), google::protobuf::internal::ConstantInitialized()))'
google/protobuf/unittest_lite.pb.cc:97:5: in 'constexpr' expansion of '((protobuf_unittest::TestAllTypesLite*)this)->protobuf_unittest::TestAllTypesLite::default_string_.google::protobuf::internal::ArenaStringPtr::ArenaStringPtr(0)'
../../src/google/protobuf/arenastring.h:179:9: in 'constexpr' expansion of '((google::protobuf::internal::ArenaStringPtr*)this)->google::protobuf::internal::ArenaStringPtr::tagged_ptr_.google::protobuf::internal::TaggedPtr<std::__cxx11::basic_string<char> >::TaggedPtr(default_value)'
../../src/google/protobuf/arenastring.h:95:14: error: conversion of 'const google::protobuf::internal::ExplicitlyConstructed<std::__cxx11::basic_string<char> >*' null pointer to 'google::protobuf::internal::ExplicitlyConstructed<std::__cxx11::basic_string<char> >*' is not a constant expression
95 | : ptr_(const_cast<ExplicitlyConstructed<std::string>*>(ptr)) {}
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It seems that const_cast can't be used in a constexpr expression, so the constinit instantiation failed.
Note: one way to avoid reinterpret_cast or other kind of forbidden casts in constexpr expression might be to use some union struct having the multiple types you want to cast things into.
Cheers,
Romain
The text was updated successfully, but these errors were encountered:
acozzette
added a commit
to acozzette/protobuf
that referenced
this issue
Feb 19, 2021
Our use of constinit does not seem to work with GCC yet (see
protocolbuffers#8310), so this
commit disables it on GCC for now.
This commit also updates mutex.h to work around the fact that MinGW's
std::mutex apparently does not have a constexpr constructor. We already
have this kind of workaround for MSVC, so we can just use the same
workaround.
Our use of constinit does not seem to work with GCC yet (see
#8310), so this
commit disables it on GCC for now.
This commit also updates mutex.h to work around the fact that MinGW's
std::mutex apparently does not have a constexpr constructor. We already
have this kind of workaround for MSVC, so we can just use the same
workaround.
Hi,
All is in the title: I tried to compile protobuf 3.15.0 with gcc trunk and -std=gnu++20, and it fails with this error:
It seems that const_cast can't be used in a constexpr expression, so the constinit instantiation failed.
Note: one way to avoid reinterpret_cast or other kind of forbidden casts in constexpr expression might be to use some union struct having the multiple types you want to cast things into.
Cheers,
Romain
The text was updated successfully, but these errors were encountered: