From db10d463860154c889ca054013b1b47a294d267e Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 4 May 2026 14:30:20 -0700 Subject: [PATCH] Change inlined_vector internal consistency assertions to ABSL_ASSERT from ABSL_HARDENING_ASSERT Several assertions check invariants based on a small set of known callers, rather than being spatial-safety-related bounds checks. ABSL_ASSERT is better suited for these checks than ABSL_HARDENING_ASSERT. PiperOrigin-RevId: 910245176 Change-Id: I7bdeba57219a0d52a359c1af757ee4af4c021ce9 --- absl/container/internal/inlined_vector.h | 33 ++++++++++++------------ 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/absl/container/internal/inlined_vector.h b/absl/container/internal/inlined_vector.h index 42878ac4..9f1919a7 100644 --- a/absl/container/internal/inlined_vector.h +++ b/absl/container/internal/inlined_vector.h @@ -500,18 +500,17 @@ class Storage { // { using V = ValueType; - ABSL_HARDENING_ASSERT( - other_storage.GetIsAllocated() || - (std::is_same>::value && - ( - // First case above - absl::is_trivially_relocatable::value || - // Second case above - (std::is_trivially_move_assignable::value && - std::is_trivially_destructible::value) || - // Third case above - (std::is_trivially_copy_constructible::value || - std::is_trivially_copy_assignable::value)))); + ABSL_ASSERT(other_storage.GetIsAllocated() || + (std::is_same>::value && + ( + // First case above + absl::is_trivially_relocatable::value || + // Second case above + (std::is_trivially_move_assignable::value && + std::is_trivially_destructible::value) || + // Third case above + (std::is_trivially_copy_constructible::value || + std::is_trivially_copy_assignable::value)))); } GetSizeAndIsAllocated() = other_storage.GetSizeAndIsAllocated(); @@ -575,7 +574,7 @@ void Storage::DestroyContents() { template void Storage::InitFrom(const Storage& other) { const SizeType n = other.GetSize(); - ABSL_HARDENING_ASSERT(n > 0); // Empty sources handled handled in caller. + ABSL_ASSERT(n > 0); // Empty sources handled in caller. ConstPointer src; Pointer dst; if (!other.GetIsAllocated()) { @@ -613,8 +612,8 @@ template auto Storage::Initialize(ValueAdapter values, SizeType new_size) -> void { // Only callable from constructors! - ABSL_HARDENING_ASSERT(!GetIsAllocated()); - ABSL_HARDENING_ASSERT(GetSize() == 0); + ABSL_ASSERT(!GetIsAllocated()); + ABSL_ASSERT(GetSize() == 0); Pointer construct_data; if (new_size > GetInlinedCapacity()) { @@ -930,7 +929,7 @@ auto Storage::Reserve(SizeType requested_capacity) -> void { template auto Storage::ShrinkToFit() -> void { // May only be called on allocated instances! - ABSL_HARDENING_ASSERT(GetIsAllocated()); + ABSL_ASSERT(GetIsAllocated()); StorageView storage_view{GetAllocatedData(), GetSize(), GetAllocatedCapacity()}; @@ -979,7 +978,7 @@ auto Storage::ShrinkToFit() -> void { template auto Storage::Swap(Storage* other_storage_ptr) -> void { using std::swap; - ABSL_HARDENING_ASSERT(this != other_storage_ptr); + ABSL_ASSERT(this != other_storage_ptr); if (GetIsAllocated() && other_storage_ptr->GetIsAllocated()) { swap(data_.allocated, other_storage_ptr->data_.allocated);