Skip to content

Commit 9f5be07

Browse files
Fix generation of HasExtension and ExtensionSize functions to restrict 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
1 parent 00298fd commit 9f5be07

File tree

2 files changed

+44
-22
lines changed

2 files changed

+44
-22
lines changed

src/google/protobuf/compiler/cpp/message.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,8 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) {
754754
// names.
755755
p->Emit(R"cc(
756756
template <typename _proto_TypeTraits, $pbi$::FieldType _field_type,
757-
bool _is_packed>
757+
bool _is_packed,
758+
typename = typename _proto_TypeTraits::Singular>
758759
inline bool HasExtension(
759760
const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits,
760761
_field_type, _is_packed>& id) const {
@@ -774,7 +775,8 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) {
774775
}
775776
776777
template <typename _proto_TypeTraits, $pbi$::FieldType _field_type,
777-
bool _is_packed>
778+
bool _is_packed,
779+
typename = typename _proto_TypeTraits::Repeated>
778780
inline int ExtensionSize(
779781
const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits,
780782
_field_type, _is_packed>& id) const {

src/google/protobuf/descriptor.pb.h

Lines changed: 40 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)