diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index c694a8b7c6..9f82fc6241 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -667,14 +667,15 @@ #ifdef PROTOBUF_CONSTINIT #error PROTOBUF_CONSTINIT was previously defined #endif -#if defined(__cpp_constinit) +#if defined(__cpp_constinit) && !defined(_MSC_VER) #define PROTOBUF_CONSTINIT constinit #define PROTOBUF_CONSTEXPR constexpr // Some older Clang versions incorrectly raise an error about // constant-initializing weak default instance pointers. Versions 12.0 and // higher seem to work, except that XCode 12.5.1 shows the error even though it // uses Clang 12.0.5. -#elif __has_cpp_attribute(clang::require_constant_initialization) && \ +// Clang-cl on Windows raises error also. +#elif !defined(_MSC_VER) && __has_cpp_attribute(clang::require_constant_initialization) && \ ((defined(__APPLE__) && __clang_major__ >= 13) || \ (!defined(__APPLE__) && __clang_major__ >= 12)) #define PROTOBUF_CONSTINIT [[clang::require_constant_initialization]] @@ -682,6 +683,10 @@ #elif PROTOBUF_GNUC_MIN(12, 2) #define PROTOBUF_CONSTINIT __constinit #define PROTOBUF_CONSTEXPR constexpr +// MSVC 17 currently seems to raise an error about constant-initialized pointers. +#elif defined(_MSC_VER) && _MSC_VER >= 1930 +#define PROTOBUF_CONSTINIT +#define PROTOBUF_CONSTEXPR constexpr #else #define PROTOBUF_CONSTINIT #define PROTOBUF_CONSTEXPR