Skip to content
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

error C2127: illegal initialization of 'constinit' entity with a non-constant expression #9698

Closed
chronoxor opened this issue Mar 29, 2022 · 6 comments · Fixed by #10232
Closed
Assignees
Labels

Comments

@chronoxor
Copy link
Contributor

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;
}
@jorgbrown
Copy link
Contributor

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

@chronoxor
Copy link
Contributor Author

chronoxor commented May 11, 2022

Here is a reproduced issue in godbolt - https://godbolt.org/z/jn8arf97f

@romanholidaypancakes
Copy link

same problem in v3.21.1(msvc c++ lastest)

@fowles fowles assigned jorgbrown and unassigned acozzette Jun 28, 2022
@jgcodes2020
Copy link

The bug seems like it would be caused by #10159.

@huysuper
Copy link

huysuper commented Jul 8, 2022

The release 3.2x.x have these issues
I have tested with v3.19.4 it works well
When I trace the change of src\google\protobuf\port_def.inc and I see the commit overrides this pull request #8690
This is the cause we can not build on Visual Studio 2019 Update 16.10
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants
@acozzette @chronoxor @jorgbrown @huysuper @jgcodes2020 @romanholidaypancakes @mkruskal-google and others