Skip to content

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

@maxgolov

Description

@maxgolov

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__.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions