error C2127: illegal initialization of 'constinit' entity with a non-constant expression
Closed this issue · 5 comments
What version of protobuf and what language are you using?
Version: master
Language: C++
What operating system (Linux, Windows, ...) and version?
Windows 10
What runtime / compiler are you using (e.g., python version or gcc version)
Visual Studio 2022
What did you do?
repeated Order orders
protobuf definition generates compile error in Visual Studio 2022
trade.pb.cc(53,111): error C2127: 'Trade::protobuf::_Account_default_instance_': illegal initialization of 'constinit' entity with a non-constant expression
for the following .proto file:
syntax = "proto3";
package Trade.protobuf;
message Order
{
int32 id = 1;
string symbol = 2;
}
message Account
{
int32 id = 1;
string name = 2;
repeated Order orders = 3;
}
FWIW, I copied the generated code, or at least, enough of it to allow Account_default_instance to be defined, and was unable to reproduce this error. https://godbolt.org/z/j97bvjq44
Here is a reproduced issue in godbolt - https://godbolt.org/z/jn8arf97f
same problem in v3.21.1(msvc c++ lastest)
The bug seems like it would be caused by #10159.