Fix uses of __cpp_lib_constexpr_string (#18890) The intent of these checks was that if the C++20 version of this feature are enabled to execute the top codepath. libstdc++ 12 defines this feature as: ```cpp // in: /usr/include/c++/12/bits/basic_string.h #ifdef __cpp_lib_is_constant_evaluated // Support P0980R1 in C++20. # define __cpp_lib_constexpr_string 201907L #elif __cplusplus >= 201703L && _GLIBCXX_HAVE_IS_CONSTANT_EVALUATED // Support P0426R1 changes to char_traits in C++17. # define __cpp_lib_constexpr_string 201611L #endif ``` So this codepath was always being hit even with -std=c++17 and then resulted in a failure because the string wasn't actually constinit. This matches the other use of this feature check in `inlined_string_field.h` Closes #18890 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/18890 from keith:ks/fix-uses-of-__cpp_lib_constexpr_string edb4f5f6b6818496e56706a58b6db21315a83c22 PiperOrigin-RevId: 696526963
diff --git a/csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs b/csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs deleted file mode 100644 index 208ce1f..0000000 --- a/csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs +++ /dev/null
@@ -1,17 +0,0 @@ -#region Copyright notice and license -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd -#endregion - -namespace Google.Protobuf.Reflection; - -internal sealed partial class FeatureSetDescriptor -{ - // Canonical serialized form of the edition defaults, generated by embed_edition_defaults. - private const string DefaultsBase64 = - "ChMYhAciACoMCAEQAhgCIAMoATACChMY5wciACoMCAIQARgBIAIoATABChMY6AciDAgBEAEYASACKAEwASoAIOYHKOgH"; -}
diff --git a/src/google/protobuf/port.cc b/src/google/protobuf/port.cc index 0261a94..af668e9 100644 --- a/src/google/protobuf/port.cc +++ b/src/google/protobuf/port.cc
@@ -97,7 +97,7 @@ } } -#if defined(__cpp_lib_constexpr_string) +#if defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT const GlobalEmptyString fixed_address_empty_string{}; #else
diff --git a/src/google/protobuf/port.h b/src/google/protobuf/port.h index ec00308..8931d43 100644 --- a/src/google/protobuf/port.h +++ b/src/google/protobuf/port.h
@@ -454,7 +454,7 @@ // Default empty string object. Don't use this directly. Instead, call // GetEmptyString() to get the reference. This empty string is aligned with a // minimum alignment of 8 bytes to match the requirement of ArenaStringPtr. -#if defined(__cpp_lib_constexpr_string) +#if defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L // Take advantage of C++20 constexpr support in std::string. class alignas(8) GlobalEmptyString { public: