Skip to content

Commit e5b3805

Browse files
ClaytonKnittelcopybara-github
authored andcommitted
Stamp out destructor calls to message objects in cel::Unique.
PiperOrigin-RevId: 945944423
1 parent bc6a2e2 commit e5b3805

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

common/memory.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,11 @@ class ABSL_ATTRIBUTE_TRIVIAL_ABI [[nodiscard]] Unique final {
599599
friend struct std::pointer_traits<Unique<T>>;
600600
friend struct ArenaTraits<Unique<T>>;
601601

602+
static constexpr bool kNeedsArenaDestructor =
603+
!std::is_trivially_destructible_v<T> &&
604+
!google::protobuf::Arena::is_destructor_skippable<T>::value &&
605+
!std::is_base_of_v<google::protobuf::MessageLite, T>;
606+
602607
Unique(T* ptr, uintptr_t arena) noexcept : ptr_(ptr), arena_(arena) {}
603608

604609
Unique(T* ptr, google::protobuf::Arena* arena, bool unowned = false) noexcept
@@ -619,8 +624,7 @@ class ABSL_ATTRIBUTE_TRIVIAL_ABI [[nodiscard]] Unique final {
619624
if ((arena_ & common_internal::kUniqueArenaBits) ==
620625
common_internal::kUniqueArenaUnownedBit) {
621626
// We never registered the destructor, call it if necessary.
622-
if constexpr (!std::is_trivially_destructible_v<T> &&
623-
!google::protobuf::Arena::is_destructor_skippable<T>::value) {
627+
if constexpr (kNeedsArenaDestructor) {
624628
std::destroy_at(ptr_);
625629
}
626630
}
@@ -631,8 +635,7 @@ class ABSL_ATTRIBUTE_TRIVIAL_ABI [[nodiscard]] Unique final {
631635
}
632636

633637
void PreRelease() noexcept {
634-
if constexpr (!std::is_trivially_destructible_v<T> &&
635-
!google::protobuf::Arena::is_destructor_skippable<T>::value) {
638+
if constexpr (kNeedsArenaDestructor) {
636639
if (static_cast<bool>(*this) &&
637640
(arena_ & common_internal::kUniqueArenaBits) ==
638641
common_internal::kUniqueArenaUnownedBit) {

0 commit comments

Comments
 (0)