Skip to content

Commit

Permalink
Annotate absl::InlinedVector to warn when unused.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 691547968
Change-Id: I41055f6840e7d08a5ba239f17e73632abc8f028d
  • Loading branch information
ckennelly authored and copybara-github committed Oct 30, 2024
1 parent fa58881 commit 9ae4bb8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion absl/container/inlined_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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>;
Expand Down
6 changes: 4 additions & 2 deletions absl/container/inlined_vector_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9ae4bb8

Please sign in to comment.