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

opentelemetry::proto::common::v1::_KeyValue_default_instance_: illegal initialization of constinit entity with a non-constant expression (C++20) #819

Closed
maxgolov opened this issue Jun 2, 2021 · 2 comments · Fixed by #820
Assignees
Labels
bug Something isn't working

Comments

@maxgolov
Copy link
Contributor

maxgolov commented Jun 2, 2021

Building with latest version of Visual Studio 2019 - update 16.10.0 , C++20 - using -std:c++latest , generated protobufs fail with this error:

image

Something related to this code here:

// Our use of constinit does not yet work with GCC:
// https://github.com/protocolbuffers/protobuf/issues/8310
#if defined(__cpp_constinit) && !defined(__GNUC__)
#define PROTOBUF_CONSTINIT constinit
#elif defined(__has_cpp_attribute)
#if __has_cpp_attribute(clang::require_constant_initialization)
#define PROTOBUF_CONSTINIT [[clang::require_constant_initialization]]
#endif
#endif
#ifndef PROTOBUF_CONSTINIT
#define PROTOBUF_CONSTINIT
#endif

Since it used to work before, I wonder if it's related to 16.10.0 now defining __cpp_constinit. My speculation at this point that I'm using slightly older version of all dependencies (via vcpkg), and maybe missing this protobuf fix:

2021-04-06 version 3.16.0 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)
...
  C++ 
  * Fix PROTOBUF_CONSTINIT macro redefinition (#8323)

And most likely the code still works well with Visual Studio 2019 update 16.9.x. Need to dig deeper to understand the best solution, most likely starting with pulling the latest protobuf. And checking if latest vs2019 compiler works well with latest protobuf. If not, possibly applying a patch to disable PROTOBUF_CONSTINIT how it's done for __GNUC__.

@maxgolov maxgolov added the bug Something isn't working label Jun 2, 2021
@maxgolov maxgolov changed the title 'opentelemetry::proto::common::v1::_KeyValue_default_instance_': illegal initialization of 'constinit' entity with a non-constant expression opentelemetry::proto::common::v1::_KeyValue_default_instance_: illegal initialization of constinit entity with a non-constant expression (C++20) Jun 2, 2021
@maxgolov
Copy link
Contributor Author

maxgolov commented Jun 2, 2021

From latest Visual Studio 2019 release notes. That addition now breaks the slightly older protobuf we are using:

image

I am not sure if there is a fix in latest protobuf or not, i.e. if we maybe need to pick up the fix. Worst case: if there is no fix in mainline protobuf, then we need to apply our local vcpkg port file with a patch on top of protobuf port_def.inc header. To use it for Windows builds of SDK with Visual Studio 2019. That patch should disable constint the same way as it is presently done for __GNUC__ ... Then the code should compile again even with latest Visual Studio 2019 16.10.0 and above in C++20 mode.

@maxgolov
Copy link
Contributor Author

maxgolov commented Jun 2, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant