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
This commit is contained in:
Abseil Team
2026-05-04 14:30:20 -07:00
committed by Copybara-Service
parent 49fe184484
commit db10d46386

View File

@@ -500,18 +500,17 @@ class Storage {
//
{
using V = ValueType<A>;
ABSL_HARDENING_ASSERT(
other_storage.GetIsAllocated() ||
(std::is_same<A, std::allocator<V>>::value &&
(
// First case above
absl::is_trivially_relocatable<V>::value ||
// Second case above
(std::is_trivially_move_assignable<V>::value &&
std::is_trivially_destructible<V>::value) ||
// Third case above
(std::is_trivially_copy_constructible<V>::value ||
std::is_trivially_copy_assignable<V>::value))));
ABSL_ASSERT(other_storage.GetIsAllocated() ||
(std::is_same<A, std::allocator<V>>::value &&
(
// First case above
absl::is_trivially_relocatable<V>::value ||
// Second case above
(std::is_trivially_move_assignable<V>::value &&
std::is_trivially_destructible<V>::value) ||
// Third case above
(std::is_trivially_copy_constructible<V>::value ||
std::is_trivially_copy_assignable<V>::value))));
}
GetSizeAndIsAllocated() = other_storage.GetSizeAndIsAllocated();
@@ -575,7 +574,7 @@ void Storage<T, N, A>::DestroyContents() {
template <typename T, size_t N, typename A>
void Storage<T, N, A>::InitFrom(const Storage& other) {
const SizeType<A> n = other.GetSize();
ABSL_HARDENING_ASSERT(n > 0); // Empty sources handled handled in caller.
ABSL_ASSERT(n > 0); // Empty sources handled in caller.
ConstPointer<A> src;
Pointer<A> dst;
if (!other.GetIsAllocated()) {
@@ -613,8 +612,8 @@ template <typename ValueAdapter>
auto Storage<T, N, A>::Initialize(ValueAdapter values,
SizeType<A> new_size) -> void {
// Only callable from constructors!
ABSL_HARDENING_ASSERT(!GetIsAllocated());
ABSL_HARDENING_ASSERT(GetSize() == 0);
ABSL_ASSERT(!GetIsAllocated());
ABSL_ASSERT(GetSize() == 0);
Pointer<A> construct_data;
if (new_size > GetInlinedCapacity()) {
@@ -930,7 +929,7 @@ auto Storage<T, N, A>::Reserve(SizeType<A> requested_capacity) -> void {
template <typename T, size_t N, typename A>
auto Storage<T, N, A>::ShrinkToFit() -> void {
// May only be called on allocated instances!
ABSL_HARDENING_ASSERT(GetIsAllocated());
ABSL_ASSERT(GetIsAllocated());
StorageView<A> storage_view{GetAllocatedData(), GetSize(),
GetAllocatedCapacity()};
@@ -979,7 +978,7 @@ auto Storage<T, N, A>::ShrinkToFit() -> void {
template <typename T, size_t N, typename A>
auto Storage<T, N, A>::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);