New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C++ port_def.inc: don't set PROTOBUF_CONSTINIT on mingw-w64 #8299
Conversation
Signed-off-by: Christopher Degawa <ccom@randomderp.com>
Currently errors out any clang compilation on windows with mingw-w64 as std::mutex is not set with constexpr full error: ```c++ ../../src/google/protobuf/struct.pb.cc:42:76: error: variable does not have a constant initializer PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY StructDefaultTypeInternal _Struct_default_instance_; ^~~~~~~~~~~~~~~~~~~~~~~~~ ../../src/google/protobuf/struct.pb.cc:42:1: note: required by 'require_constant_initialization' attribute here PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY StructDefaultTypeInternal _Struct_default_instance_; ^~~~~~~~~~~~~~~~~~ ../../src\google/protobuf/port_def.inc:580:30: note: expanded from macro 'PROTOBUF_CONSTINIT' \#define PROTOBUF_CONSTINIT [[clang::require_constant_initialization]] ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../src\google/protobuf/stubs/mutex.h:132:17: note: non-constexpr constructor 'mutex' cannot be used in a constant expression std::mutex mu_{}; ^ ../../src\google/protobuf/map_field.h:336:9: note: in call to 'WrappedMutex()' mutex_(GOOGLE_PROTOBUF_LINKER_INITIALIZED), ^ ../../src\google/protobuf/map_field.h:485:9: note: in call to 'MapFieldBase({})' : MapFieldBase(tag) {} ^ ../../src\google/protobuf/map_field.h:546:9: note: in call to 'TypeDefinedMapFieldBase({})' : TypeDefinedMapFieldBase<Key, T>(tag), impl_() {} ^ ../../src/google/protobuf/struct.pb.cc:33:5: note: in call to 'MapField({})' : fields_(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}){} ^ ../../src/google/protobuf/struct.pb.cc:36:7: note: in call to 'Struct({})' : _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {} ^ ../../src/google/protobuf/struct.pb.cc:42:76: note: in call to 'StructDefaultTypeInternal()' PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY StructDefaultTypeInternal _Struct_default_instance_; ^ D:\mabs\msys64\mingw64\include\c++\10.2.0\bits/std_mutex.h:91:5: note: declared here mutex() noexcept = default; ^ 1 error generated. ``` Signed-off-by: Christopher Degawa <ccom@randomderp.com>
How can I set a tag to fixed the Mergeable issue? |
@1480c1 I added the tags to fix the Mergeable error and run the CI tests. However I wonder if there is a better solution. Ideally we want to always set |
Based on my limited understanding of https://sourceforge.net/p/mingw-w64/mailman/mingw-w64-public/thread/2a2daec1.69321.14d0ff963e9.Coremail.lh_mouse%40126.com/ and https://sourceforge.net/p/mingw-w64/mailman/mingw-w64-public/thread/1360a75.a67e5.15412d233d0.Coremail.lh_mouse%40126.com/, this seems to be an issue inside the version of windows that gcc is compatible with, but @lhmouse can probably elaborate a bit more edit notes: https://devblogs.microsoft.com/cppblog/constexpr-complete-for-vs-2015-rtm-c-11-compiler-c-17-stl/
which leads me to assume gcc has |
That has been fixed since couple of years ago: mingw-w64/mingw-w64@8bba2a9 |
Then is msys2's mingw-w64/clang broken? |
It's because libstdc++'s mutex has a non-trivial destructor and is not a literal type. Why would you want a |
I'm not sure why we need a constexpr mutex, but we have this same problem with MSVC and work around it here:
|
A
Note that constant initialization with constructors marked |
That pr fixes compilation issues on both gcc and clang |
A class with a You may declare the object (which has a non-static mutex member) as
You don't tell the compiler to do the right thing (https://gcc.godbolt.org/z/b3c9Ts). |
Currently errors out any clang compilation on windows with mingw-w64 as std::mutex is not set with constexpr
full error: