about summary refs log tree commit diff
path: root/absl/container
diff options
context:
space:
mode:
Diffstat (limited to 'absl/container')
-rw-r--r--absl/container/BUILD.bazel60
-rw-r--r--absl/container/inlined_vector.h19
-rw-r--r--absl/container/internal/raw_hash_set_test.cc4
3 files changed, 66 insertions, 17 deletions
diff --git a/absl/container/BUILD.bazel b/absl/container/BUILD.bazel
index cd914baf88b7..066a98862d5f 100644
--- a/absl/container/BUILD.bazel
+++ b/absl/container/BUILD.bazel
@@ -17,6 +17,7 @@
 load(
     "//absl:copts/configure_copts.bzl",
     "ABSL_DEFAULT_COPTS",
+    "ABSL_DEFAULT_LINKOPTS",
     "ABSL_EXCEPTIONS_FLAG",
     "ABSL_EXCEPTIONS_FLAG_LINKOPTS",
     "ABSL_TEST_COPTS",
@@ -30,6 +31,7 @@ cc_library(
     name = "compressed_tuple",
     hdrs = ["internal/compressed_tuple.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         "//absl/utility",
     ],
@@ -39,6 +41,7 @@ cc_test(
     name = "compressed_tuple_test",
     srcs = ["internal/compressed_tuple_test.cc"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":compressed_tuple",
         "//absl/memory",
@@ -51,6 +54,7 @@ cc_library(
     name = "fixed_array",
     hdrs = ["fixed_array.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":compressed_tuple",
         "//absl/algorithm",
@@ -65,7 +69,7 @@ cc_test(
     name = "fixed_array_test",
     srcs = ["fixed_array_test.cc"],
     copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG,
-    linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS,
+    linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":fixed_array",
         "//absl/base:exception_testing",
@@ -79,6 +83,7 @@ cc_test(
     name = "fixed_array_test_noexceptions",
     srcs = ["fixed_array_test.cc"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":fixed_array",
         "//absl/base:exception_testing",
@@ -92,7 +97,7 @@ cc_test(
     name = "fixed_array_exception_safety_test",
     srcs = ["fixed_array_exception_safety_test.cc"],
     copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG,
-    linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS,
+    linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":fixed_array",
         "//absl/base:exception_safety_testing",
@@ -104,6 +109,7 @@ cc_test(
     name = "fixed_array_benchmark",
     srcs = ["fixed_array_benchmark.cc"],
     copts = ABSL_TEST_COPTS + ["$(STACK_FRAME_UNLIMITED)"],
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     tags = ["benchmark"],
     deps = [
         ":fixed_array",
@@ -115,6 +121,7 @@ cc_library(
     name = "inlined_vector_internal",
     hdrs = ["internal/inlined_vector.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         "//absl/meta:type_traits",
     ],
@@ -124,6 +131,7 @@ cc_library(
     name = "inlined_vector",
     hdrs = ["inlined_vector.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":inlined_vector_internal",
         "//absl/algorithm",
@@ -138,6 +146,7 @@ cc_library(
     testonly = 1,
     hdrs = ["internal/counting_allocator.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     visibility = ["//visibility:private"],
 )
 
@@ -145,7 +154,7 @@ cc_test(
     name = "inlined_vector_test",
     srcs = ["inlined_vector_test.cc"],
     copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG,
-    linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS,
+    linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS + ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":counting_allocator",
         ":inlined_vector",
@@ -164,6 +173,7 @@ cc_test(
     name = "inlined_vector_test_noexceptions",
     srcs = ["inlined_vector_test.cc"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":counting_allocator",
         ":inlined_vector",
@@ -182,6 +192,7 @@ cc_test(
     name = "inlined_vector_benchmark",
     srcs = ["inlined_vector_benchmark.cc"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     tags = ["benchmark"],
     deps = [
         ":inlined_vector",
@@ -197,6 +208,7 @@ cc_library(
     srcs = ["internal/test_instance_tracker.cc"],
     hdrs = ["internal/test_instance_tracker.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     visibility = [
         "//absl:__subpackages__",
     ],
@@ -206,6 +218,7 @@ cc_test(
     name = "test_instance_tracker_test",
     srcs = ["internal/test_instance_tracker_test.cc"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":test_instance_tracker",
         "@com_google_googletest//:gtest_main",
@@ -230,6 +243,7 @@ cc_library(
     name = "flat_hash_map",
     hdrs = ["flat_hash_map.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":container_memory",
         ":hash_function_defaults",
@@ -243,6 +257,7 @@ cc_test(
     name = "flat_hash_map_test",
     srcs = ["flat_hash_map_test.cc"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     tags = NOTEST_TAGS_NONMOBILE,
     deps = [
         ":flat_hash_map",
@@ -260,6 +275,7 @@ cc_library(
     name = "flat_hash_set",
     hdrs = ["flat_hash_set.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":container_memory",
         ":hash_function_defaults",
@@ -274,6 +290,7 @@ cc_test(
     name = "flat_hash_set_test",
     srcs = ["flat_hash_set_test.cc"],
     copts = ABSL_TEST_COPTS + ["-DUNORDERED_SET_CXX17"],
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     tags = NOTEST_TAGS_NONMOBILE,
     deps = [
         ":flat_hash_set",
@@ -292,6 +309,7 @@ cc_library(
     name = "node_hash_map",
     hdrs = ["node_hash_map.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":container_memory",
         ":hash_function_defaults",
@@ -306,6 +324,7 @@ cc_test(
     name = "node_hash_map_test",
     srcs = ["node_hash_map_test.cc"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     tags = NOTEST_TAGS_NONMOBILE,
     deps = [
         ":hash_generator_testing",
@@ -323,6 +342,7 @@ cc_library(
     name = "node_hash_set",
     hdrs = ["node_hash_set.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":hash_function_defaults",
         ":node_hash_policy",
@@ -336,6 +356,7 @@ cc_test(
     name = "node_hash_set_test",
     srcs = ["node_hash_set_test.cc"],
     copts = ABSL_TEST_COPTS + ["-DUNORDERED_SET_CXX17"],
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     tags = NOTEST_TAGS_NONMOBILE,
     deps = [
         ":node_hash_set",
@@ -351,6 +372,7 @@ cc_library(
     name = "container_memory",
     hdrs = ["internal/container_memory.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         "//absl/memory",
         "//absl/utility",
@@ -361,6 +383,7 @@ cc_test(
     name = "container_memory_test",
     srcs = ["internal/container_memory_test.cc"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     tags = NOTEST_TAGS_NONMOBILE,
     deps = [
         ":container_memory",
@@ -373,6 +396,7 @@ cc_library(
     name = "hash_function_defaults",
     hdrs = ["internal/hash_function_defaults.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         "//absl/base:config",
         "//absl/hash",
@@ -384,6 +408,7 @@ cc_test(
     name = "hash_function_defaults_test",
     srcs = ["internal/hash_function_defaults_test.cc"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     tags = NOTEST_TAGS,
     deps = [
         ":hash_function_defaults",
@@ -399,6 +424,7 @@ cc_library(
     srcs = ["internal/hash_generator_testing.cc"],
     hdrs = ["internal/hash_generator_testing.h"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":hash_policy_testing",
         "//absl/meta:type_traits",
@@ -411,6 +437,7 @@ cc_library(
     testonly = 1,
     hdrs = ["internal/hash_policy_testing.h"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         "//absl/hash",
         "//absl/strings",
@@ -421,6 +448,7 @@ cc_test(
     name = "hash_policy_testing_test",
     srcs = ["internal/hash_policy_testing_test.cc"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":hash_policy_testing",
         "@com_google_googletest//:gtest_main",
@@ -431,6 +459,7 @@ cc_library(
     name = "hash_policy_traits",
     hdrs = ["internal/hash_policy_traits.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = ["//absl/meta:type_traits"],
 )
 
@@ -438,6 +467,7 @@ cc_test(
     name = "hash_policy_traits_test",
     srcs = ["internal/hash_policy_traits_test.cc"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":hash_policy_traits",
         "@com_google_googletest//:gtest_main",
@@ -448,6 +478,7 @@ cc_library(
     name = "hashtable_debug",
     hdrs = ["internal/hashtable_debug.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":hashtable_debug_hooks",
     ],
@@ -457,6 +488,7 @@ cc_library(
     name = "hashtable_debug_hooks",
     hdrs = ["internal/hashtable_debug_hooks.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
 )
 
 cc_library(
@@ -467,6 +499,7 @@ cc_library(
     ],
     hdrs = ["internal/hashtablez_sampler.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":have_sse",
         "//absl/base",
@@ -481,6 +514,7 @@ cc_library(
 cc_test(
     name = "hashtablez_sampler_test",
     srcs = ["internal/hashtablez_sampler_test.cc"],
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":hashtablez_sampler",
         ":have_sse",
@@ -496,12 +530,14 @@ cc_library(
     name = "node_hash_policy",
     hdrs = ["internal/node_hash_policy.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
 )
 
 cc_test(
     name = "node_hash_policy_test",
     srcs = ["internal/node_hash_policy_test.cc"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":hash_policy_traits",
         ":node_hash_policy",
@@ -513,6 +549,7 @@ cc_library(
     name = "raw_hash_map",
     hdrs = ["internal/raw_hash_map.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":container_memory",
         ":raw_hash_set",
@@ -523,6 +560,7 @@ cc_library(
     name = "have_sse",
     hdrs = ["internal/have_sse.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     visibility = ["//visibility:private"],
 )
 
@@ -530,6 +568,7 @@ cc_library(
     name = "common",
     hdrs = ["internal/common.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         "//absl/meta:type_traits",
         "//absl/types:optional",
@@ -541,6 +580,7 @@ cc_library(
     srcs = ["internal/raw_hash_set.cc"],
     hdrs = ["internal/raw_hash_set.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":common",
         ":compressed_tuple",
@@ -584,6 +624,7 @@ cc_test(
     size = "small",
     srcs = ["internal/raw_hash_set_allocator_test.cc"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":raw_hash_set",
         ":tracked",
@@ -596,6 +637,7 @@ cc_library(
     name = "layout",
     hdrs = ["internal/layout.h"],
     copts = ABSL_DEFAULT_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         "//absl/base:core_headers",
         "//absl/meta:type_traits",
@@ -610,6 +652,7 @@ cc_test(
     size = "small",
     srcs = ["internal/layout_test.cc"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     tags = NOTEST_TAGS,
     visibility = ["//visibility:private"],
     deps = [
@@ -626,6 +669,7 @@ cc_library(
     testonly = 1,
     hdrs = ["internal/tracked.h"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
 )
 
 cc_library(
@@ -633,6 +677,7 @@ cc_library(
     testonly = 1,
     hdrs = ["internal/unordered_map_constructor_test.h"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":hash_generator_testing",
         ":hash_policy_testing",
@@ -645,6 +690,7 @@ cc_library(
     testonly = 1,
     hdrs = ["internal/unordered_map_lookup_test.h"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":hash_generator_testing",
         ":hash_policy_testing",
@@ -657,6 +703,7 @@ cc_library(
     testonly = 1,
     hdrs = ["internal/unordered_map_modifiers_test.h"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":hash_generator_testing",
         ":hash_policy_testing",
@@ -669,6 +716,7 @@ cc_library(
     testonly = 1,
     hdrs = ["internal/unordered_set_constructor_test.h"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":hash_generator_testing",
         ":hash_policy_testing",
@@ -682,6 +730,7 @@ cc_library(
     testonly = 1,
     hdrs = ["internal/unordered_set_members_test.h"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         "//absl/meta:type_traits",
         "@com_google_googletest//:gtest",
@@ -693,6 +742,7 @@ cc_library(
     testonly = 1,
     hdrs = ["internal/unordered_map_members_test.h"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         "//absl/meta:type_traits",
         "@com_google_googletest//:gtest",
@@ -704,6 +754,7 @@ cc_library(
     testonly = 1,
     hdrs = ["internal/unordered_set_lookup_test.h"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":hash_generator_testing",
         ":hash_policy_testing",
@@ -716,6 +767,7 @@ cc_library(
     testonly = 1,
     hdrs = ["internal/unordered_set_modifiers_test.h"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":hash_generator_testing",
         ":hash_policy_testing",
@@ -727,6 +779,7 @@ cc_test(
     name = "unordered_set_test",
     srcs = ["internal/unordered_set_test.cc"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     tags = NOTEST_TAGS_NONMOBILE,
     deps = [
         ":unordered_set_constructor_test",
@@ -741,6 +794,7 @@ cc_test(
     name = "unordered_map_test",
     srcs = ["internal/unordered_map_test.cc"],
     copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
     tags = NOTEST_TAGS_NONMOBILE,
     deps = [
         ":unordered_map_constructor_test",
diff --git a/absl/container/inlined_vector.h b/absl/container/inlined_vector.h
index 77988058e913..bd4ed6667ad2 100644
--- a/absl/container/inlined_vector.h
+++ b/absl/container/inlined_vector.h
@@ -454,7 +454,7 @@ class InlinedVector {
   // Overload of `InlinedVector::operator=()` to replace the contents of the
   // inlined vector with the contents of `other`.
   InlinedVector& operator=(const InlinedVector& other) {
-    if (ABSL_PREDICT_FALSE(this == &other)) return *this;
+    if (ABSL_PREDICT_FALSE(this == std::addressof(other))) return *this;
 
     // Optimized to avoid reallocation.
     // Prefer reassignment to copy construction for elements.
@@ -475,7 +475,7 @@ class InlinedVector {
   // NOTE: As a result of calling this overload, `other` may be empty or it's
   // contents may be left in a moved-from state.
   InlinedVector& operator=(InlinedVector&& other) {
-    if (ABSL_PREDICT_FALSE(this == &other)) return *this;
+    if (ABSL_PREDICT_FALSE(this == std::addressof(other))) return *this;
 
     if (other.allocated()) {
       clear();
@@ -840,7 +840,7 @@ class InlinedVector {
   //
   // Swaps the contents of this inlined vector with the contents of `other`.
   void swap(InlinedVector& other) {
-    if (ABSL_PREDICT_FALSE(this == &other)) return;
+    if (ABSL_PREDICT_FALSE(this == std::addressof(other))) return;
 
     SwapImpl(other);
   }
@@ -864,7 +864,8 @@ class InlinedVector {
   }
 
   void init_allocation(const Allocation& allocation) {
-    new (&storage_.rep_.allocation_storage.allocation) Allocation(allocation);
+    new (static_cast<void*>(std::addressof(
+        storage_.rep_.allocation_storage.allocation))) Allocation(allocation);
   }
 
   // TODO(absl-team): investigate whether the reinterpret_cast is appropriate.
@@ -1154,7 +1155,7 @@ class InlinedVector {
     if (!allocated() && !other.allocated()) {
       // Both inlined: swap up to smaller size, then move remaining elements.
       InlinedVector* a = this;
-      InlinedVector* b = &other;
+      InlinedVector* b = std::addressof(other);
       if (size() < other.size()) {
         swap(a, b);
       }
@@ -1186,7 +1187,7 @@ class InlinedVector {
     // pointer/capacity into the originally inlined vector and swap
     // the tags.
     InlinedVector* a = this;
-    InlinedVector* b = &other;
+    InlinedVector* b = std::addressof(other);
     if (a->allocated()) {
       swap(a, b);
     }
@@ -1305,10 +1306,4 @@ auto AbslHashValue(H h, const InlinedVector<TheT, TheN, TheA>& v) -> H {
 }
 }  // namespace absl
 
-// -----------------------------------------------------------------------------
-// Implementation of InlinedVector
-//
-// Do not depend on any below implementation details!
-// -----------------------------------------------------------------------------
-
 #endif  // ABSL_CONTAINER_INLINED_VECTOR_H_
diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc
index 02fd0bfa0d93..4d94f7853219 100644
--- a/absl/container/internal/raw_hash_set_test.cc
+++ b/absl/container/internal/raw_hash_set_test.cc
@@ -1785,7 +1785,7 @@ TEST(Table, IterationOrderChangesByInstance) {
 
     std::vector<IntTable> tables;
     bool found_difference = false;
-    for (int i = 0; !found_difference && i < 500; ++i) {
+    for (int i = 0; !found_difference && i < 5000; ++i) {
       tables.push_back(MakeSimpleTable(size));
       found_difference = OrderOfIteration(tables.back()) != reference;
     }
@@ -1799,7 +1799,7 @@ TEST(Table, IterationOrderChangesByInstance) {
 
 TEST(Table, IterationOrderChangesOnRehash) {
   std::vector<IntTable> garbage;
-  for (int i = 0; i < 500; ++i) {
+  for (int i = 0; i < 5000; ++i) {
     auto t = MakeSimpleTable(20);
     const auto reference = OrderOfIteration(t);
     // Force rehash to the same size.