From 61b059f79e8c2acf1f9bd0d48b07cbff9d7e5a06 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Wed, 29 Mar 2023 17:35:26 -0700 Subject: inlined_vector: fix incorrect conditions for move constructor fast paths. These have nothing to do with copy construction or copy assignment, and using "is trivially copy constructible" can in theory even give the wrong result if the copy constructor is trivial but the move constructor is not. PiperOrigin-RevId: 520488816 Change-Id: I6da4d57f3ce23b03044e0bf9aa70a14b51651fa3 --- absl/container/internal/inlined_vector.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'absl/container/internal/inlined_vector.h') diff --git a/absl/container/internal/inlined_vector.h b/absl/container/internal/inlined_vector.h index 6397db48..4e628424 100644 --- a/absl/container/internal/inlined_vector.h +++ b/absl/container/internal/inlined_vector.h @@ -510,16 +510,20 @@ class Storage { // // * It's possible to trivially copy construct/assign the elements. // - // TODO(b/274984172): the conditions here, preserved from historical ones, - // don't actually implement this. They are far too conservative (they don't - // work for move-only types, and require both copyability and - // assignability). - ABSL_HARDENING_ASSERT( - other_storage.GetIsAllocated() || - (std::is_same>>::value && - absl::is_trivially_copy_constructible>::value && - absl::is_trivially_copy_assignable>::value && - absl::is_trivially_destructible>::value)); + { + using V = ValueType; + ABSL_HARDENING_ASSERT( + other_storage.GetIsAllocated() || + (std::is_same>::value && + ( + // First case above + ((absl::is_trivially_move_constructible::value || + absl::is_trivially_move_assignable::value) && + absl::is_trivially_destructible::value) || + // Second case above + (absl::is_trivially_copy_constructible::value || + absl::is_trivially_copy_assignable::value)))); + } GetSizeAndIsAllocated() = other_storage.GetSizeAndIsAllocated(); data_ = other_storage.data_; -- cgit v1.2.3