diff --git a/src/google/protobuf/generated_message_util.cc b/src/google/protobuf/generated_message_util.cc index 8f86f6087456..cf5d6fe729a7 100644 --- a/src/google/protobuf/generated_message_util.cc +++ b/src/google/protobuf/generated_message_util.cc @@ -72,15 +72,10 @@ void DestroyString(const void* s) { static_cast(s)->~basic_string(); } -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY EmptyString - fixed_address_empty_string; // NOLINT - - PROTOBUF_CONSTINIT std::atomic init_protobuf_defaults_state{false}; static bool InitProtobufDefaultsImpl() { - ::new (static_cast(&fixed_address_empty_string.value)) std::string(); - OnShutdownDestroyString(&fixed_address_empty_string.value); + ::new (static_cast(&fixed_address_empty_string().value)) std::string(); + OnShutdownDestroyString(&fixed_address_empty_string().value); // Verify that we can indeed get the address during constant evaluation. PROTOBUF_CONSTINIT static const std::string& fixed_address_empty_string_test = diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h index 87e9d2b4ccfa..828b75b683f1 100644 --- a/src/google/protobuf/message_lite.h +++ b/src/google/protobuf/message_lite.h @@ -165,11 +165,13 @@ union EmptyString { // Default empty string object. Don't use this directly. Instead, call // GetEmptyString() to get the reference. -PROTOBUF_EXPORT extern EmptyString fixed_address_empty_string; - +PROTOBUF_EXPORT constexpr const EmptyString& fixed_address_empty_string() { + PROTOBUF_CONSTINIT static const EmptyString emptyStringInstance; + return emptyStringInstance; +}; PROTOBUF_EXPORT constexpr const std::string& GetEmptyStringAlreadyInited() { - return fixed_address_empty_string.value; + return fixed_address_empty_string().value; } PROTOBUF_EXPORT size_t StringSpaceUsedExcludingSelfLong(const std::string& str);