In edition 2024, `Enum_Name(value)` functions return `absl::string_view` by default.

Added enum feature `enum_name_uses_string_view` to turn back to the old behavior returning `const std::string&`.

PiperOrigin-RevId: 655637240
pull/17590/head
Protobuf Team Bot 4 months ago committed by Copybara-Service
parent 75b66c2cde
commit e3fa6aac29
  1. 6
      editions/generated_files_test.cc
  2. 18
      src/google/protobuf/compiler/cpp/enum.cc
  3. 2
      src/google/protobuf/cpp_edition_defaults.h
  4. 114
      src/google/protobuf/cpp_features.pb.cc
  5. 73
      src/google/protobuf/cpp_features.pb.h
  6. 11
      src/google/protobuf/cpp_features.proto
  7. 375
      src/google/protobuf/descriptor_unittest.cc
  8. 3
      src/google/protobuf/lite_unittest.cc
  9. 10
      src/google/protobuf/unittest_lite_edition_2024.proto

@ -146,7 +146,11 @@ TEST(Generated, EditionDefaults2023InternalFeatures) {
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING }
[pb.cpp] {
legacy_closed_enum: false
string_type: STRING
enum_name_uses_string_view: false
}
)pb"));
}

@ -24,6 +24,7 @@
#include "absl/container/btree_set.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/cpp/generator.h"
#include "google/protobuf/compiler/cpp/helpers.h"
#include "google/protobuf/compiler/cpp/names.h"
#include "google/protobuf/descriptor.h"
@ -49,6 +50,11 @@ absl::flat_hash_map<absl::string_view, std::string> EnumVars(
enum_->containing_type() == nullptr ? "" : absl::StrCat(classname, "_")},
{"kMin", absl::StrCat(min->number())},
{"kMax", absl::StrCat(max->number())},
{"return_type", CppGenerator::GetResolvedSourceFeatures(*enum_)
.GetExtension(::pb::cpp)
.enum_name_uses_string_view()
? "::absl::string_view"
: "const std::string&"},
};
}
@ -182,7 +188,7 @@ void EnumGenerator::GenerateDefinition(io::Printer* p) {
)cc");
} else {
p->Emit(R"cc(
const std::string& $Msg_Enum$_Name($Msg_Enum$ value);
$return_type$ $Msg_Enum$_Name($Msg_Enum$ value);
)cc");
}
@ -204,7 +210,7 @@ void EnumGenerator::GenerateDefinition(io::Printer* p) {
if (should_cache_ || !has_reflection_) {
p->Emit({{"static_assert", write_assert}}, R"cc(
template <typename T>
const std::string& $Msg_Enum$_Name(T value) {
$return_type$ $Msg_Enum$_Name(T value) {
$static_assert$;
return $Msg_Enum$_Name(static_cast<$Msg_Enum$>(value));
}
@ -216,7 +222,7 @@ void EnumGenerator::GenerateDefinition(io::Printer* p) {
// pointers, so if the enum values are sparse, it's not worth it.
p->Emit(R"cc(
template <>
inline const std::string& $Msg_Enum$_Name($Msg_Enum$ value) {
inline $return_type$ $Msg_Enum$_Name($Msg_Enum$ value) {
return ::$proto_ns$::internal::NameOfDenseEnum<$Msg_Enum$_descriptor,
$kMin$, $kMax$>(
static_cast<int>(value));
@ -226,7 +232,7 @@ void EnumGenerator::GenerateDefinition(io::Printer* p) {
} else {
p->Emit({{"static_assert", write_assert}}, R"cc(
template <typename T>
const std::string& $Msg_Enum$_Name(T value) {
$return_type$ $Msg_Enum$_Name(T value) {
$static_assert$;
return ::$proto_ns$::internal::NameOfEnum($Msg_Enum$_descriptor(), value);
}
@ -322,7 +328,7 @@ void EnumGenerator::GenerateSymbolImports(io::Printer* p) const {
p->Emit(R"cc(
template <typename T>
static inline const std::string& $Enum$_Name(T value) {
static inline $return_type$ $Enum$_Name(T value) {
return $Msg_Enum$_Name(value);
}
static inline bool $Enum$_Parse(absl::string_view name, $Enum_$* value) {
@ -514,7 +520,7 @@ void EnumGenerator::GenerateMethods(int idx, io::Printer* p) {
$entries_by_number$,
};
const std::string& $Msg_Enum$_Name($Msg_Enum$ value) {
$return_type$ $Msg_Enum$_Name($Msg_Enum$ value) {
static const bool kDummy =
::$proto_ns$::internal::InitializeEnumStrings(
$Msg_Enum$_entries, $Msg_Enum$_entries_by_number,

@ -5,7 +5,7 @@
// the C++ runtime. This is used for feature resolution under Editions.
// NOLINTBEGIN
// clang-format off
#define PROTOBUF_INTERNAL_CPP_EDITION_DEFAULTS "\n\035\030\204\007\"\003\302>\000*\023\010\001\020\002\030\002 \003(\0010\002\302>\004\010\001\020\003\n\035\030\347\007\"\003\302>\000*\023\010\002\020\001\030\001 \002(\0010\001\302>\004\010\000\020\003\n\035\030\350\007\"\023\010\001\020\001\030\001 \002(\0010\001\302>\004\010\000\020\003*\003\302>\000\n\035\030\351\007\"\023\010\001\020\001\030\001 \002(\0010\001\302>\004\010\000\020\001*\003\302>\000 \346\007(\351\007"
#define PROTOBUF_INTERNAL_CPP_EDITION_DEFAULTS "\n\037\030\204\007\"\003\302>\000*\025\010\001\020\002\030\002 \003(\0010\002\302>\006\010\001\020\003\030\000\n\037\030\347\007\"\003\302>\000*\025\010\002\020\001\030\001 \002(\0010\001\302>\006\010\000\020\003\030\000\n\037\030\350\007\"\023\010\001\020\001\030\001 \002(\0010\001\302>\004\010\000\020\003*\005\302>\002\030\000\n\037\030\351\007\"\025\010\001\020\001\030\001 \002(\0010\001\302>\006\010\000\020\001\030\001*\003\302>\000 \346\007(\351\007"
// clang-format on
// NOLINTEND

@ -28,8 +28,9 @@ namespace pb {
inline constexpr CppFeatures::Impl_::Impl_(
::_pbi::ConstantInitialized) noexcept
: _cached_size_{0},
string_type_{static_cast< ::pb::CppFeatures_StringType >(0)},
legacy_closed_enum_{false},
string_type_{static_cast< ::pb::CppFeatures_StringType >(0)} {}
enum_name_uses_string_view_{false} {}
template <typename>
PROTOBUF_CONSTEXPR CppFeatures::CppFeatures(::_pbi::ConstantInitialized)
@ -67,13 +68,15 @@ const ::uint32_t
~0u, // no sizeof(Split)
PROTOBUF_FIELD_OFFSET(::pb::CppFeatures, _impl_.legacy_closed_enum_),
PROTOBUF_FIELD_OFFSET(::pb::CppFeatures, _impl_.string_type_),
0,
PROTOBUF_FIELD_OFFSET(::pb::CppFeatures, _impl_.enum_name_uses_string_view_),
1,
0,
2,
};
static const ::_pbi::MigrationSchema
schemas[] ABSL_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
{0, 10, -1, sizeof(::pb::CppFeatures)},
{0, 11, -1, sizeof(::pb::CppFeatures)},
};
static const ::_pb::Message* const file_default_instances[] = {
&::pb::_CppFeatures_default_instance_._instance,
@ -81,7 +84,7 @@ static const ::_pb::Message* const file_default_instances[] = {
const char descriptor_table_protodef_google_2fprotobuf_2fcpp_5ffeatures_2eproto[] ABSL_ATTRIBUTE_SECTION_VARIABLE(
protodesc_cold) = {
"\n\"google/protobuf/cpp_features.proto\022\002pb"
"\032 google/protobuf/descriptor.proto\"\256\003\n\013C"
"\032 google/protobuf/descriptor.proto\"\374\003\n\013C"
"ppFeatures\022\373\001\n\022legacy_closed_enum\030\001 \001(\010B"
"\336\001\210\001\001\230\001\004\230\001\001\242\001\t\022\004true\030\204\007\242\001\n\022\005false\030\347\007\262\001\270\001"
"\010\350\007\020\350\007\032\257\001The legacy closed enum treatmen"
@ -90,11 +93,13 @@ const char descriptor_table_protodef_google_2fprotobuf_2fcpp_5ffeatures_2eproto[
"m type on the enum definitions themselve"
"s rather than on fields.\022Z\n\013string_type\030"
"\002 \001(\0162\032.pb.CppFeatures.StringTypeB)\210\001\001\230\001"
"\004\230\001\001\242\001\013\022\006STRING\030\204\007\242\001\t\022\004VIEW\030\351\007\262\001\003\010\350\007\"E\n\n"
"StringType\022\027\n\023STRING_TYPE_UNKNOWN\020\000\022\010\n\004V"
"IEW\020\001\022\010\n\004CORD\020\002\022\n\n\006STRING\020\003::\n\003cpp\022\033.goo"
"gle.protobuf.FeatureSet\030\350\007 \001(\0132\017.pb.CppF"
"eatures"
"\004\230\001\001\242\001\013\022\006STRING\030\204\007\242\001\t\022\004VIEW\030\351\007\262\001\003\010\350\007\022L\n\032"
"enum_name_uses_string_view\030\003 \001(\010B(\210\001\002\230\001\006"
"\230\001\001\242\001\n\022\005false\030\204\007\242\001\t\022\004true\030\351\007\262\001\003\010\351\007\"E\n\nSt"
"ringType\022\027\n\023STRING_TYPE_UNKNOWN\020\000\022\010\n\004VIE"
"W\020\001\022\010\n\004CORD\020\002\022\n\n\006STRING\020\003::\n\003cpp\022\033.googl"
"e.protobuf.FeatureSet\030\350\007 \001(\0132\017.pb.CppFea"
"tures"
};
static const ::_pbi::DescriptorTable* const descriptor_table_google_2fprotobuf_2fcpp_5ffeatures_2eproto_deps[1] =
{
@ -104,7 +109,7 @@ static ::absl::once_flag descriptor_table_google_2fprotobuf_2fcpp_5ffeatures_2ep
PROTOBUF_CONSTINIT const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fcpp_5ffeatures_2eproto = {
false,
false,
567,
645,
descriptor_table_protodef_google_2fprotobuf_2fcpp_5ffeatures_2eproto,
"google/protobuf/cpp_features.proto",
&descriptor_table_google_2fprotobuf_2fcpp_5ffeatures_2eproto_once,
@ -172,11 +177,11 @@ inline PROTOBUF_NDEBUG_INLINE CppFeatures::Impl_::Impl_(
inline void CppFeatures::SharedCtor(::_pb::Arena* arena) {
new (&_impl_) Impl_(internal_visibility(), arena);
::memset(reinterpret_cast<char *>(&_impl_) +
offsetof(Impl_, legacy_closed_enum_),
offsetof(Impl_, string_type_),
0,
offsetof(Impl_, string_type_) -
offsetof(Impl_, legacy_closed_enum_) +
sizeof(Impl_::string_type_));
offsetof(Impl_, enum_name_uses_string_view_) -
offsetof(Impl_, string_type_) +
sizeof(Impl_::enum_name_uses_string_view_));
}
CppFeatures::~CppFeatures() {
// @@protoc_insertion_point(destructor:pb.CppFeatures)
@ -217,15 +222,15 @@ const ::google::protobuf::MessageLite::ClassData* CppFeatures::GetClassData() co
return _class_data_.base();
}
PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1
const ::_pbi::TcParseTable<1, 2, 1, 0, 2> CppFeatures::_table_ = {
const ::_pbi::TcParseTable<2, 3, 1, 0, 2> CppFeatures::_table_ = {
{
PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_._has_bits_),
0, // no _extensions_
2, 8, // max_field_number, fast_idx_mask
3, 24, // max_field_number, fast_idx_mask
offsetof(decltype(_table_), field_lookup_table),
4294967292, // skipmap
4294967288, // skipmap
offsetof(decltype(_table_), field_entries),
2, // num_field_entries
3, // num_field_entries
1, // num_aux_entries
offsetof(decltype(_table_), aux_entries),
_class_data_.base(),
@ -235,21 +240,28 @@ const ::_pbi::TcParseTable<1, 2, 1, 0, 2> CppFeatures::_table_ = {
::_pbi::TcParser::GetTable<::pb::CppFeatures>(), // to_prefetch
#endif // PROTOBUF_PREFETCH_PARSE_TABLE
}, {{
{::_pbi::TcParser::MiniParse, {}},
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
{::_pbi::TcParser::SingularVarintNoZag1<bool, offsetof(CppFeatures, _impl_.legacy_closed_enum_), 1>(),
{8, 1, 0, PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.legacy_closed_enum_)}},
// optional .pb.CppFeatures.StringType string_type = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
{::_pbi::TcParser::FastEr0S1,
{16, 1, 3, PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.string_type_)}},
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
{::_pbi::TcParser::SingularVarintNoZag1<bool, offsetof(CppFeatures, _impl_.legacy_closed_enum_), 0>(),
{8, 0, 0, PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.legacy_closed_enum_)}},
{16, 0, 3, PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.string_type_)}},
// optional bool enum_name_uses_string_view = 3 [retention = RETENTION_SOURCE, targets = TARGET_TYPE_ENUM, targets = TARGET_TYPE_FILE, edition_defaults = {
{::_pbi::TcParser::SingularVarintNoZag1<bool, offsetof(CppFeatures, _impl_.enum_name_uses_string_view_), 2>(),
{24, 2, 0, PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.enum_name_uses_string_view_)}},
}}, {{
65535, 65535
}}, {{
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
{PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.legacy_closed_enum_), _Internal::kHasBitsOffset + 0, 0,
{PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.legacy_closed_enum_), _Internal::kHasBitsOffset + 1, 0,
(0 | ::_fl::kFcOptional | ::_fl::kBool)},
// optional .pb.CppFeatures.StringType string_type = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
{PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.string_type_), _Internal::kHasBitsOffset + 1, 0,
{PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.string_type_), _Internal::kHasBitsOffset + 0, 0,
(0 | ::_fl::kFcOptional | ::_fl::kEnumRange)},
// optional bool enum_name_uses_string_view = 3 [retention = RETENTION_SOURCE, targets = TARGET_TYPE_ENUM, targets = TARGET_TYPE_FILE, edition_defaults = {
{PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.enum_name_uses_string_view_), _Internal::kHasBitsOffset + 2, 0,
(0 | ::_fl::kFcOptional | ::_fl::kBool)},
}}, {{
{0, 4},
}}, {{
@ -264,10 +276,10 @@ PROTOBUF_NOINLINE void CppFeatures::Clear() {
(void) cached_has_bits;
cached_has_bits = _impl_._has_bits_[0];
if (cached_has_bits & 0x00000003u) {
::memset(&_impl_.legacy_closed_enum_, 0, static_cast<::size_t>(
reinterpret_cast<char*>(&_impl_.string_type_) -
reinterpret_cast<char*>(&_impl_.legacy_closed_enum_)) + sizeof(_impl_.string_type_));
if (cached_has_bits & 0x00000007u) {
::memset(&_impl_.string_type_, 0, static_cast<::size_t>(
reinterpret_cast<char*>(&_impl_.enum_name_uses_string_view_) -
reinterpret_cast<char*>(&_impl_.string_type_)) + sizeof(_impl_.enum_name_uses_string_view_));
}
_impl_._has_bits_.Clear();
_internal_metadata_.Clear<::google::protobuf::UnknownFieldSet>();
@ -290,19 +302,26 @@ PROTOBUF_NOINLINE void CppFeatures::Clear() {
cached_has_bits = this_._impl_._has_bits_[0];
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
if (cached_has_bits & 0x00000001u) {
if (cached_has_bits & 0x00000002u) {
target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteBoolToArray(
1, this_._internal_legacy_closed_enum(), target);
}
// optional .pb.CppFeatures.StringType string_type = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
if (cached_has_bits & 0x00000002u) {
if (cached_has_bits & 0x00000001u) {
target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteEnumToArray(
2, this_._internal_string_type(), target);
}
// optional bool enum_name_uses_string_view = 3 [retention = RETENTION_SOURCE, targets = TARGET_TYPE_ENUM, targets = TARGET_TYPE_FILE, edition_defaults = {
if (cached_has_bits & 0x00000004u) {
target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteBoolToArray(
3, this_._internal_enum_name_uses_string_view(), target);
}
if (PROTOBUF_PREDICT_FALSE(this_._internal_metadata_.have_unknown_fields())) {
target =
::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray(
@ -328,16 +347,20 @@ PROTOBUF_NOINLINE void CppFeatures::Clear() {
::_pbi::Prefetch5LinesFrom7Lines(&this_);
cached_has_bits = this_._impl_._has_bits_[0];
if (cached_has_bits & 0x00000003u) {
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
if (cached_has_bits & 0x00000001u) {
total_size += 2;
}
if (cached_has_bits & 0x00000007u) {
// optional .pb.CppFeatures.StringType string_type = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
if (cached_has_bits & 0x00000002u) {
if (cached_has_bits & 0x00000001u) {
total_size += 1 +
::_pbi::WireFormatLite::EnumSize(this_._internal_string_type());
}
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
if (cached_has_bits & 0x00000002u) {
total_size += 2;
}
// optional bool enum_name_uses_string_view = 3 [retention = RETENTION_SOURCE, targets = TARGET_TYPE_ENUM, targets = TARGET_TYPE_FILE, edition_defaults = {
if (cached_has_bits & 0x00000004u) {
total_size += 2;
}
}
return this_.MaybeComputeUnknownFieldsSize(total_size,
&this_._impl_._cached_size_);
@ -352,12 +375,15 @@ void CppFeatures::MergeImpl(::google::protobuf::MessageLite& to_msg, const ::goo
(void) cached_has_bits;
cached_has_bits = from._impl_._has_bits_[0];
if (cached_has_bits & 0x00000003u) {
if (cached_has_bits & 0x00000007u) {
if (cached_has_bits & 0x00000001u) {
_this->_impl_.legacy_closed_enum_ = from._impl_.legacy_closed_enum_;
_this->_impl_.string_type_ = from._impl_.string_type_;
}
if (cached_has_bits & 0x00000002u) {
_this->_impl_.string_type_ = from._impl_.string_type_;
_this->_impl_.legacy_closed_enum_ = from._impl_.legacy_closed_enum_;
}
if (cached_has_bits & 0x00000004u) {
_this->_impl_.enum_name_uses_string_view_ = from._impl_.enum_name_uses_string_view_;
}
}
_this->_impl_._has_bits_[0] |= cached_has_bits;
@ -377,11 +403,11 @@ void CppFeatures::InternalSwap(CppFeatures* PROTOBUF_RESTRICT other) {
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
::google::protobuf::internal::memswap<
PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.string_type_)
+ sizeof(CppFeatures::_impl_.string_type_)
- PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.legacy_closed_enum_)>(
reinterpret_cast<char*>(&_impl_.legacy_closed_enum_),
reinterpret_cast<char*>(&other->_impl_.legacy_closed_enum_));
PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.enum_name_uses_string_view_)
+ sizeof(CppFeatures::_impl_.enum_name_uses_string_view_)
- PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.string_type_)>(
reinterpret_cast<char*>(&_impl_.string_type_),
reinterpret_cast<char*>(&other->_impl_.string_type_));
}
::google::protobuf::Metadata CppFeatures::GetMetadata() const {

@ -261,9 +261,21 @@ class PROTOBUF_EXPORT CppFeatures final : public ::google::protobuf::Message
// accessors -------------------------------------------------------
enum : int {
kLegacyClosedEnumFieldNumber = 1,
kStringTypeFieldNumber = 2,
kLegacyClosedEnumFieldNumber = 1,
kEnumNameUsesStringViewFieldNumber = 3,
};
// optional .pb.CppFeatures.StringType string_type = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
bool has_string_type() const;
void clear_string_type() ;
::pb::CppFeatures_StringType string_type() const;
void set_string_type(::pb::CppFeatures_StringType value);
private:
::pb::CppFeatures_StringType _internal_string_type() const;
void _internal_set_string_type(::pb::CppFeatures_StringType value);
public:
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
bool has_legacy_closed_enum() const;
void clear_legacy_closed_enum() ;
@ -275,15 +287,15 @@ class PROTOBUF_EXPORT CppFeatures final : public ::google::protobuf::Message
void _internal_set_legacy_closed_enum(bool value);
public:
// optional .pb.CppFeatures.StringType string_type = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
bool has_string_type() const;
void clear_string_type() ;
::pb::CppFeatures_StringType string_type() const;
void set_string_type(::pb::CppFeatures_StringType value);
// optional bool enum_name_uses_string_view = 3 [retention = RETENTION_SOURCE, targets = TARGET_TYPE_ENUM, targets = TARGET_TYPE_FILE, edition_defaults = {
bool has_enum_name_uses_string_view() const;
void clear_enum_name_uses_string_view() ;
bool enum_name_uses_string_view() const;
void set_enum_name_uses_string_view(bool value);
private:
::pb::CppFeatures_StringType _internal_string_type() const;
void _internal_set_string_type(::pb::CppFeatures_StringType value);
bool _internal_enum_name_uses_string_view() const;
void _internal_set_enum_name_uses_string_view(bool value);
public:
// @@protoc_insertion_point(class_scope:pb.CppFeatures)
@ -291,7 +303,7 @@ class PROTOBUF_EXPORT CppFeatures final : public ::google::protobuf::Message
class _Internal;
friend class ::google::protobuf::internal::TcParser;
static const ::google::protobuf::internal::TcParseTable<
1, 2, 1,
2, 3, 1,
0, 2>
_table_;
@ -312,8 +324,9 @@ class PROTOBUF_EXPORT CppFeatures final : public ::google::protobuf::Message
const CppFeatures& from_msg);
::google::protobuf::internal::HasBits<1> _has_bits_;
::google::protobuf::internal::CachedSize _cached_size_;
bool legacy_closed_enum_;
int string_type_;
bool legacy_closed_enum_;
bool enum_name_uses_string_view_;
PROTOBUF_TSAN_DECLARE_MEMBER
};
union { Impl_ _impl_; };
@ -343,13 +356,13 @@ PROTOBUF_EXPORT extern ::google::protobuf::internal::ExtensionIdentifier<
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
inline bool CppFeatures::has_legacy_closed_enum() const {
bool value = (_impl_._has_bits_[0] & 0x00000001u) != 0;
bool value = (_impl_._has_bits_[0] & 0x00000002u) != 0;
return value;
}
inline void CppFeatures::clear_legacy_closed_enum() {
::google::protobuf::internal::TSanWrite(&_impl_);
_impl_.legacy_closed_enum_ = false;
_impl_._has_bits_[0] &= ~0x00000001u;
_impl_._has_bits_[0] &= ~0x00000002u;
}
inline bool CppFeatures::legacy_closed_enum() const {
// @@protoc_insertion_point(field_get:pb.CppFeatures.legacy_closed_enum)
@ -357,7 +370,7 @@ inline bool CppFeatures::legacy_closed_enum() const {
}
inline void CppFeatures::set_legacy_closed_enum(bool value) {
_internal_set_legacy_closed_enum(value);
_impl_._has_bits_[0] |= 0x00000001u;
_impl_._has_bits_[0] |= 0x00000002u;
// @@protoc_insertion_point(field_set:pb.CppFeatures.legacy_closed_enum)
}
inline bool CppFeatures::_internal_legacy_closed_enum() const {
@ -371,13 +384,13 @@ inline void CppFeatures::_internal_set_legacy_closed_enum(bool value) {
// optional .pb.CppFeatures.StringType string_type = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
inline bool CppFeatures::has_string_type() const {
bool value = (_impl_._has_bits_[0] & 0x00000002u) != 0;
bool value = (_impl_._has_bits_[0] & 0x00000001u) != 0;
return value;
}
inline void CppFeatures::clear_string_type() {
::google::protobuf::internal::TSanWrite(&_impl_);
_impl_.string_type_ = 0;
_impl_._has_bits_[0] &= ~0x00000002u;
_impl_._has_bits_[0] &= ~0x00000001u;
}
inline ::pb::CppFeatures_StringType CppFeatures::string_type() const {
// @@protoc_insertion_point(field_get:pb.CppFeatures.string_type)
@ -385,7 +398,7 @@ inline ::pb::CppFeatures_StringType CppFeatures::string_type() const {
}
inline void CppFeatures::set_string_type(::pb::CppFeatures_StringType value) {
_internal_set_string_type(value);
_impl_._has_bits_[0] |= 0x00000002u;
_impl_._has_bits_[0] |= 0x00000001u;
// @@protoc_insertion_point(field_set:pb.CppFeatures.string_type)
}
inline ::pb::CppFeatures_StringType CppFeatures::_internal_string_type() const {
@ -398,6 +411,34 @@ inline void CppFeatures::_internal_set_string_type(::pb::CppFeatures_StringType
_impl_.string_type_ = value;
}
// optional bool enum_name_uses_string_view = 3 [retention = RETENTION_SOURCE, targets = TARGET_TYPE_ENUM, targets = TARGET_TYPE_FILE, edition_defaults = {
inline bool CppFeatures::has_enum_name_uses_string_view() const {
bool value = (_impl_._has_bits_[0] & 0x00000004u) != 0;
return value;
}
inline void CppFeatures::clear_enum_name_uses_string_view() {
::google::protobuf::internal::TSanWrite(&_impl_);
_impl_.enum_name_uses_string_view_ = false;
_impl_._has_bits_[0] &= ~0x00000004u;
}
inline bool CppFeatures::enum_name_uses_string_view() const {
// @@protoc_insertion_point(field_get:pb.CppFeatures.enum_name_uses_string_view)
return _internal_enum_name_uses_string_view();
}
inline void CppFeatures::set_enum_name_uses_string_view(bool value) {
_internal_set_enum_name_uses_string_view(value);
_impl_._has_bits_[0] |= 0x00000004u;
// @@protoc_insertion_point(field_set:pb.CppFeatures.enum_name_uses_string_view)
}
inline bool CppFeatures::_internal_enum_name_uses_string_view() const {
::google::protobuf::internal::TSanRead(&_impl_);
return _impl_.enum_name_uses_string_view_;
}
inline void CppFeatures::_internal_set_enum_name_uses_string_view(bool value) {
::google::protobuf::internal::TSanWrite(&_impl_);
_impl_.enum_name_uses_string_view_ = value;
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif // __GNUC__

@ -53,4 +53,15 @@ message CppFeatures {
edition_defaults = { edition: EDITION_LEGACY, value: "STRING" },
edition_defaults = { edition: EDITION_2024, value: "VIEW" }
];
optional bool enum_name_uses_string_view = 3 [
retention = RETENTION_SOURCE,
targets = TARGET_TYPE_ENUM,
targets = TARGET_TYPE_FILE,
feature_support = {
edition_introduced: EDITION_2024,
},
edition_defaults = { edition: EDITION_LEGACY, value: "false" },
edition_defaults = { edition: EDITION_2024, value: "true" }
];
}

@ -7546,33 +7546,42 @@ TEST_F(FeaturesTest, Proto2Features) {
EXPECT_THAT(file->options(), EqualsProto(""));
EXPECT_EQ(GetFeatures(file).GetExtension(pb::test).file_feature(),
pb::VALUE1);
EXPECT_THAT(
GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: NONE
message_encoding: LENGTH_PREFIXED
json_format: LEGACY_BEST_EFFORT
[pb.cpp] { legacy_closed_enum: true string_type: STRING })pb"));
EXPECT_THAT(
GetCoreFeatures(field), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: NONE
message_encoding: LENGTH_PREFIXED
json_format: LEGACY_BEST_EFFORT
[pb.cpp] { legacy_closed_enum: true string_type: STRING })pb"));
EXPECT_THAT(
GetCoreFeatures(group), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: NONE
message_encoding: DELIMITED
json_format: LEGACY_BEST_EFFORT
[pb.cpp] { legacy_closed_enum: true string_type: STRING })pb"));
EXPECT_THAT(GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: NONE
message_encoding: LENGTH_PREFIXED
json_format: LEGACY_BEST_EFFORT
[pb.cpp] {
legacy_closed_enum: true
string_type: STRING
enum_name_uses_string_view: false
})pb"));
EXPECT_THAT(GetCoreFeatures(field), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: NONE
message_encoding: LENGTH_PREFIXED
json_format: LEGACY_BEST_EFFORT
[pb.cpp] {
legacy_closed_enum: true
string_type: STRING
enum_name_uses_string_view: false
})pb"));
EXPECT_THAT(GetCoreFeatures(group), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: NONE
message_encoding: DELIMITED
json_format: LEGACY_BEST_EFFORT
[pb.cpp] {
legacy_closed_enum: true
string_type: STRING
enum_name_uses_string_view: false
})pb"));
EXPECT_TRUE(field->has_presence());
EXPECT_FALSE(field->requires_utf8_validation());
EXPECT_EQ(
@ -7636,24 +7645,30 @@ TEST_F(FeaturesTest, Proto3Features) {
EXPECT_THAT(file->options(), EqualsProto(""));
EXPECT_EQ(GetFeatures(file).GetExtension(pb::test).file_feature(),
pb::VALUE2);
EXPECT_THAT(
GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
EXPECT_THAT(
GetCoreFeatures(field), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
EXPECT_THAT(GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] {
legacy_closed_enum: false
string_type: STRING
enum_name_uses_string_view: false
})pb"));
EXPECT_THAT(GetCoreFeatures(field), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] {
legacy_closed_enum: false
string_type: STRING
enum_name_uses_string_view: false
})pb"));
EXPECT_FALSE(field->has_presence());
EXPECT_FALSE(field->requires_utf8_validation());
EXPECT_EQ(
@ -7829,7 +7844,11 @@ TEST_F(FeaturesTest, Edition2023Defaults) {
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING }
[pb.cpp] {
legacy_closed_enum: false
string_type: STRING
enum_name_uses_string_view: false
}
)pb"));
// Since pb::test is registered in the pool, it should end up with defaults in
@ -7908,7 +7927,11 @@ TEST_F(FeaturesTest, Edition2024Defaults) {
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: VIEW }
[pb.cpp] {
legacy_closed_enum: false
string_type: VIEW
enum_name_uses_string_view: true
}
)pb"));
// Since pb::test is registered in the pool, it should end up with defaults in
@ -7937,7 +7960,11 @@ TEST_F(FeaturesBaseTest, DefaultEdition2023Defaults) {
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING }
[pb.cpp] {
legacy_closed_enum: false
string_type: STRING
enum_name_uses_string_view: false
}
)pb"));
EXPECT_FALSE(GetFeatures(file).HasExtension(pb::test));
}
@ -7954,15 +7981,18 @@ TEST_F(FeaturesTest, ClearsOptions) {
}
)pb");
EXPECT_THAT(file->options(), EqualsProto("java_package: 'bar'"));
EXPECT_THAT(
GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
EXPECT_THAT(GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] {
legacy_closed_enum: false
string_type: STRING
enum_name_uses_string_view: false
})pb"));
}
TEST_F(FeaturesTest, RestoresOptionsRoundTrip) {
@ -8319,15 +8349,18 @@ TEST_F(FeaturesTest, NoOptions) {
name: "foo.proto" syntax: "editions" edition: EDITION_2023
)pb");
EXPECT_EQ(&file->options(), &FileOptions::default_instance());
EXPECT_THAT(
GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
EXPECT_THAT(GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] {
legacy_closed_enum: false
string_type: STRING
enum_name_uses_string_view: false
})pb"));
}
TEST_F(FeaturesTest, InvalidEdition) {
@ -8349,15 +8382,18 @@ TEST_F(FeaturesTest, FileFeatures) {
options { features { field_presence: IMPLICIT } }
)pb");
EXPECT_THAT(file->options(), EqualsProto(""));
EXPECT_THAT(
GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
EXPECT_THAT(GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] {
legacy_closed_enum: false
string_type: STRING
enum_name_uses_string_view: false
})pb"));
}
TEST_F(FeaturesTest, FileFeaturesExtension) {
@ -8427,15 +8463,18 @@ TEST_F(FeaturesTest, MessageFeaturesDefault) {
)pb");
const Descriptor* message = file->message_type(0);
EXPECT_THAT(message->options(), EqualsProto(""));
EXPECT_THAT(
GetCoreFeatures(message), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
EXPECT_THAT(GetCoreFeatures(message), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] {
legacy_closed_enum: false
string_type: STRING
enum_name_uses_string_view: false
})pb"));
}
TEST_F(FeaturesTest, MessageFeaturesInherit) {
@ -8535,15 +8574,18 @@ TEST_F(FeaturesTest, FieldFeaturesDefault) {
)pb");
const FieldDescriptor* field = file->message_type(0)->field(0);
EXPECT_THAT(field->options(), EqualsProto(""));
EXPECT_THAT(
GetCoreFeatures(field), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
EXPECT_THAT(GetCoreFeatures(field), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] {
legacy_closed_enum: false
string_type: STRING
enum_name_uses_string_view: false
})pb"));
}
TEST_F(FeaturesTest, FieldFeaturesInherit) {
@ -9006,15 +9048,18 @@ TEST_F(FeaturesTest, EnumFeaturesDefault) {
)pb");
const EnumDescriptor* enm = file->enum_type(0);
EXPECT_THAT(enm->options(), EqualsProto(""));
EXPECT_THAT(
GetCoreFeatures(enm), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
EXPECT_THAT(GetCoreFeatures(enm), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] {
legacy_closed_enum: false
string_type: STRING
enum_name_uses_string_view: false
})pb"));
}
TEST_F(FeaturesTest, EnumFeaturesInherit) {
@ -9118,15 +9163,18 @@ TEST_F(FeaturesTest, EnumValueFeaturesDefault) {
)pb");
const EnumValueDescriptor* value = file->enum_type(0)->value(0);
EXPECT_THAT(value->options(), EqualsProto(""));
EXPECT_THAT(
GetCoreFeatures(value), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
EXPECT_THAT(GetCoreFeatures(value), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] {
legacy_closed_enum: false
string_type: STRING
enum_name_uses_string_view: false
})pb"));
}
TEST_F(FeaturesTest, EnumValueFeaturesInherit) {
@ -9214,15 +9262,18 @@ TEST_F(FeaturesTest, OneofFeaturesDefault) {
)pb");
const OneofDescriptor* oneof = file->message_type(0)->oneof_decl(0);
EXPECT_THAT(oneof->options(), EqualsProto(""));
EXPECT_THAT(
GetCoreFeatures(oneof), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
EXPECT_THAT(GetCoreFeatures(oneof), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] {
legacy_closed_enum: false
string_type: STRING
enum_name_uses_string_view: false
})pb"));
}
TEST_F(FeaturesTest, OneofFeaturesInherit) {
@ -9319,15 +9370,18 @@ TEST_F(FeaturesTest, ExtensionRangeFeaturesDefault) {
const Descriptor::ExtensionRange* range =
file->message_type(0)->extension_range(0);
EXPECT_THAT(range->options(), EqualsProto(""));
EXPECT_THAT(
GetCoreFeatures(range), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
EXPECT_THAT(GetCoreFeatures(range), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] {
legacy_closed_enum: false
string_type: STRING
enum_name_uses_string_view: false
})pb"));
}
TEST_F(FeaturesTest, ExtensionRangeFeaturesInherit) {
@ -9409,15 +9463,18 @@ TEST_F(FeaturesTest, ServiceFeaturesDefault) {
)pb");
const ServiceDescriptor* service = file->service(0);
EXPECT_THAT(service->options(), EqualsProto(""));
EXPECT_THAT(
GetCoreFeatures(service), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
EXPECT_THAT(GetCoreFeatures(service), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] {
legacy_closed_enum: false
string_type: STRING
enum_name_uses_string_view: false
})pb"));
}
TEST_F(FeaturesTest, ServiceFeaturesInherit) {
@ -9476,15 +9533,18 @@ TEST_F(FeaturesTest, MethodFeaturesDefault) {
)pb");
const MethodDescriptor* method = file->service(0)->method(0);
EXPECT_THAT(method->options(), EqualsProto(""));
EXPECT_THAT(
GetCoreFeatures(method), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
EXPECT_THAT(GetCoreFeatures(method), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] {
legacy_closed_enum: false
string_type: STRING
enum_name_uses_string_view: false
})pb"));
}
TEST_F(FeaturesTest, MethodFeaturesInherit) {
@ -10554,15 +10614,18 @@ TEST_F(FeaturesTest, UninterpretedOptions) {
}
)pb");
EXPECT_THAT(file->options(), EqualsProto(""));
EXPECT_THAT(
GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
EXPECT_THAT(GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] {
legacy_closed_enum: false
string_type: STRING
enum_name_uses_string_view: false
})pb"));
}
TEST_F(FeaturesTest, UninterpretedOptionsMerge) {

@ -12,6 +12,7 @@
#include <iostream>
#include <limits>
#include <string>
#include <type_traits>
#include <utility>
#include <gmock/gmock.h>
@ -33,6 +34,7 @@
#include "google/protobuf/unittest_lite.pb.h"
#include "google/protobuf/wire_format_lite.h"
// Must be included last
#include "google/protobuf/port_def.inc"
@ -1164,6 +1166,7 @@ TYPED_TEST(LiteTest, EnumValueToName) {
EXPECT_EQ("", protobuf_unittest::ForeignEnumLite_Name(999));
}
TYPED_TEST(LiteTest, NestedEnumValueToName) {
EXPECT_EQ("FOO", protobuf_unittest::TestAllTypesLite::NestedEnum_Name(
protobuf_unittest::TestAllTypesLite::FOO));

@ -0,0 +1,10 @@
edition = "2024";
package protobuf_unittest;
option optimize_for = LITE_RUNTIME;
enum EnumNameStringView {
ENUM_NAME_STRING_VIEW_DEFAULT = 0;
ENUM_NAME_STRING_VIEW_ANOTHER_VALUE = 1;
}
Loading…
Cancel
Save