Skip to content

Commit

Permalink
Fix generation of HasExtension and ExtensionSize functions to restric…
Browse files Browse the repository at this point in the history
…t to the

right kind of extension. This way you get a compile time failure instead of a
runtime one.
Other extension accessors already have this kind of SFINAE restrictions.

PiperOrigin-RevId: 602418580
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Jan 29, 2024
1 parent 00298fd commit 9f5be07
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
6 changes: 4 additions & 2 deletions src/google/protobuf/compiler/cpp/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,8 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) {
// names.
p->Emit(R"cc(
template <typename _proto_TypeTraits, $pbi$::FieldType _field_type,
bool _is_packed>
bool _is_packed,
typename = typename _proto_TypeTraits::Singular>
inline bool HasExtension(
const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits,
_field_type, _is_packed>& id) const {
Expand All @@ -774,7 +775,8 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) {
}
template <typename _proto_TypeTraits, $pbi$::FieldType _field_type,
bool _is_packed>
bool _is_packed,
typename = typename _proto_TypeTraits::Repeated>
inline int ExtensionSize(
const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits,
_field_type, _is_packed>& id) const {
Expand Down
60 changes: 40 additions & 20 deletions src/google/protobuf/descriptor.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9f5be07

Please sign in to comment.