mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 12:07:05 +08:00
Annotate absl::InlinedVector to warn when unused.
PiperOrigin-RevId: 691547968 Change-Id: I41055f6840e7d08a5ba239f17e73632abc8f028d
This commit is contained in:
committed by
Copybara-Service
parent
fa588813c4
commit
9ae4bb8007
@@ -46,6 +46,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "absl/algorithm/algorithm.h"
|
||||
#include "absl/base/attributes.h"
|
||||
#include "absl/base/internal/throw_delegate.h"
|
||||
#include "absl/base/macros.h"
|
||||
#include "absl/base/optimization.h"
|
||||
@@ -67,7 +68,7 @@ ABSL_NAMESPACE_BEGIN
|
||||
// as a `std::vector`. The API of the `absl::InlinedVector` within this file is
|
||||
// designed to cover the same API footprint as covered by `std::vector`.
|
||||
template <typename T, size_t N, typename A = std::allocator<T>>
|
||||
class InlinedVector {
|
||||
class ABSL_ATTRIBUTE_WARN_UNUSED InlinedVector {
|
||||
static_assert(N > 0, "`absl::InlinedVector` requires an inlined capacity.");
|
||||
|
||||
using Storage = inlined_vector_internal::Storage<T, N, A>;
|
||||
|
||||
@@ -1190,6 +1190,7 @@ TYPED_TEST_P(InstanceTest, CountConstructorsDestructorsOnCopyConstruction) {
|
||||
tracker.ResetCopiesMovesSwaps();
|
||||
{ // Copy constructor should create 'len' more instances.
|
||||
InstanceVec v_copy(v);
|
||||
EXPECT_EQ(v_copy.size(), v.size());
|
||||
EXPECT_EQ(tracker.instances(), len + len);
|
||||
EXPECT_EQ(tracker.copies(), len);
|
||||
EXPECT_EQ(tracker.moves(), 0);
|
||||
@@ -1217,6 +1218,7 @@ TYPED_TEST_P(InstanceTest, CountConstructorsDestructorsOnMoveConstruction) {
|
||||
tracker.ResetCopiesMovesSwaps();
|
||||
{
|
||||
InstanceVec v_copy(std::move(v));
|
||||
EXPECT_EQ(v_copy.size(), len);
|
||||
if (static_cast<size_t>(len) > inlined_capacity) {
|
||||
// Allocation is moved as a whole.
|
||||
EXPECT_EQ(tracker.instances(), len);
|
||||
@@ -1765,12 +1767,12 @@ TEST(AllocatorSupportTest, CountAllocations) {
|
||||
|
||||
int64_t allocated2 = 0;
|
||||
MyAlloc alloc2(&allocated2);
|
||||
AllocVec v2(v, alloc2);
|
||||
ABSL_ATTRIBUTE_UNUSED AllocVec v2(v, alloc2);
|
||||
EXPECT_THAT(allocated2, Eq(0));
|
||||
|
||||
int64_t allocated3 = 0;
|
||||
MyAlloc alloc3(&allocated3);
|
||||
AllocVec v3(std::move(v), alloc3);
|
||||
ABSL_ATTRIBUTE_UNUSED AllocVec v3(std::move(v), alloc3);
|
||||
EXPECT_THAT(allocated3, Eq(0));
|
||||
}
|
||||
EXPECT_THAT(allocated, 0);
|
||||
|
||||
Reference in New Issue
Block a user