Skip to content

Commit

Permalink
Fix build for older compilers.
Browse files Browse the repository at this point in the history
If it doesn't properly do constant initialization on globals we should
not try to call virtual functions on these objects during dynamic
initialization.
Turn off the optimization in these cases.

PiperOrigin-RevId: 619251810
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Mar 26, 2024
1 parent b5e69ae commit f5c53ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/google/protobuf/extension_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,13 @@ void ExtensionSet::RegisterMessageExtension(const MessageLite* extendee,
type == WireFormatLite::TYPE_GROUP);
ExtensionInfo info(extendee, number, type, is_repeated, is_packed,
verify_func, is_lazy);
info.message_info = {prototype, prototype->GetTcParseTable()};
info.message_info = {prototype,
#if defined(PROTOBUF_CONSTINIT_DEFAULT_INSTANCES)
prototype->GetTcParseTable()
#else
nullptr
#endif
};
Register(info);
}

Expand Down
4 changes: 3 additions & 1 deletion src/google/protobuf/extension_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ struct ExtensionInfo {

struct MessageInfo {
const MessageLite* prototype;
// The TcParse table used for this object. Never null.
// The TcParse table used for this object.
// Never null. (except in platforms that don't constant initialize default
// instances)
const internal::TcParseTableBase* tc_table;
};

Expand Down

0 comments on commit f5c53ac

Please sign in to comment.