SIGN IN SIGN UP

Protocol Buffers - Google's data interchange format

0 0 27 C++

Disable constinit on MSVC for static library builds

https://github.com/protocolbuffers/protobuf/commit/38927bf2b93a42e2a155b49f9d610c70cc5942ec cleaned up the constinit suppressions based on our understanding of the Windows/MSVC limitations at the time. It turns out this was incomplete and, by restoring constinit on static library MSVC builds, we broke something.

On MSVC, but not clang-cl, the workaround must extend to static library builds too. Although pointers to same-dll symbols are fine and MSVC, with optimizations, will avoid a static initializer, it doesn't seem to consistently recognize it in the type systems, so we can't enforce constinit. See https://godbolt.org/z/cYeYaaWq5

On MSVC, but not clang-cl, the above workaround must extend to static library builds too. MSVC can avoid a global constructor when initializing structures containing pointers to same-dll symbols, it relies on the optimizer for this, so we can't enforce constinit. This limitation does not apply to constexpr. See https://godbolt.org/z/hsT9e3zs4

Add a Windows Bazel C++20 build configuration, which would have caught this.

PiperOrigin-RevId: 858801389
P
Protobuf Team Bot committed
783da0a9407f6bf890455e5ba05e861df11f600f
Parent: 6ba0e6f
Committed by Copybara-Service <copybara-worker@google.com> on 1/21/2026, 12:25:34 AM