about summary refs log tree commit diff
path: root/absl/base
diff options
context:
space:
mode:
Diffstat (limited to 'absl/base')
-rw-r--r--absl/base/exception_safety_testing_test.cc23
-rw-r--r--absl/base/internal/exception_safety_testing.h21
2 files changed, 29 insertions, 15 deletions
diff --git a/absl/base/exception_safety_testing_test.cc b/absl/base/exception_safety_testing_test.cc
index f8baf20c9360..9c52f249ee16 100644
--- a/absl/base/exception_safety_testing_test.cc
+++ b/absl/base/exception_safety_testing_test.cc
@@ -44,7 +44,7 @@ class ThrowingValueTest : public ::testing::Test {
   void SetUp() override { UnsetCountdown(); }
 
  private:
-  AllocInspector clouseau_;
+  ConstructorTracker clouseau_;
 };
 
 TEST_F(ThrowingValueTest, Throws) {
@@ -279,7 +279,7 @@ class ThrowingAllocatorTest : public ::testing::Test {
   void SetUp() override { UnsetCountdown(); }
 
  private:
-  AllocInspector borlu_;
+  ConstructorTracker borlu_;
 };
 
 TEST_F(ThrowingAllocatorTest, MemoryManagement) {
@@ -652,22 +652,22 @@ struct Tracked : private exceptions_internal::TrackedObject {
   Tracked() : TrackedObject(ABSL_PRETTY_FUNCTION) {}
 };
 
-TEST(AllocInspectorTest, Pass) {
-  AllocInspector javert;
+TEST(ConstructorTrackerTest, Pass) {
+  ConstructorTracker javert;
   Tracked t;
 }
 
-TEST(AllocInspectorTest, NotDestroyed) {
+TEST(ConstructorTrackerTest, NotDestroyed) {
   absl::aligned_storage_t<sizeof(Tracked), alignof(Tracked)> storage;
   EXPECT_NONFATAL_FAILURE(
       {
-        AllocInspector gadget;
+        ConstructorTracker gadget;
         new (&storage) Tracked;
       },
       "not destroyed");
 }
 
-TEST(AllocInspectorTest, DestroyedTwice) {
+TEST(ConstructorTrackerTest, DestroyedTwice) {
   EXPECT_NONFATAL_FAILURE(
       {
         Tracked t;
@@ -676,7 +676,7 @@ TEST(AllocInspectorTest, DestroyedTwice) {
       "destroyed improperly");
 }
 
-TEST(AllocInspectorTest, ConstructedTwice) {
+TEST(ConstructorTrackerTest, ConstructedTwice) {
   absl::aligned_storage_t<sizeof(Tracked), alignof(Tracked)> storage;
   EXPECT_NONFATAL_FAILURE(
       {
@@ -697,5 +697,12 @@ TEST(ThrowingValueTraitsTest, RelationalOperators) {
   EXPECT_TRUE((std::is_convertible<decltype(a >= b), bool>::value));
 }
 
+TEST(ThrowingAllocatorTraitsTest, Assignablility) {
+  EXPECT_TRUE(std::is_move_assignable<ThrowingAllocator<int>>::value);
+  EXPECT_TRUE(std::is_copy_assignable<ThrowingAllocator<int>>::value);
+  EXPECT_TRUE(std::is_nothrow_move_assignable<ThrowingAllocator<int>>::value);
+  EXPECT_TRUE(std::is_nothrow_copy_assignable<ThrowingAllocator<int>>::value);
+}
+
 }  // namespace
 }  // namespace absl
diff --git a/absl/base/internal/exception_safety_testing.h b/absl/base/internal/exception_safety_testing.h
index adee848b2e90..a0cd33b4d00a 100644
--- a/absl/base/internal/exception_safety_testing.h
+++ b/absl/base/internal/exception_safety_testing.h
@@ -37,7 +37,7 @@
 namespace absl {
 struct InternalAbslNamespaceFinder {};
 
-struct AllocInspector;
+struct ConstructorTracker;
 
 // A configuration enum for Throwing*.  Operations whose flags are set will
 // throw, everything else won't.  This isn't meant to be exhaustive, more flags
@@ -125,7 +125,7 @@ class TrackedObject {
     }
   }
 
-  friend struct ::absl::AllocInspector;
+  friend struct ::absl::ConstructorTracker;
 };
 
 template <typename Factory>
@@ -594,6 +594,8 @@ class ThrowingAllocator : private exceptions_internal::TrackedObject {
       const ThrowingAllocator<U, Flags>& other) noexcept
       : TrackedObject(ABSL_PRETTY_FUNCTION), dummy_(other.State()) {}
 
+  // According to C++11 standard [17.6.3.5], Table 28, the move/copy ctors of
+  // allocator shall not exit via an exception, thus they are marked noexcept.
   ThrowingAllocator(const ThrowingAllocator& other) noexcept
       : TrackedObject(ABSL_PRETTY_FUNCTION), dummy_(other.State()) {}
 
@@ -607,6 +609,11 @@ class ThrowingAllocator : private exceptions_internal::TrackedObject {
 
   ~ThrowingAllocator() noexcept = default;
 
+  ThrowingAllocator& operator=(const ThrowingAllocator& other) noexcept {
+    dummy_ = other.State();
+    return *this;
+  }
+
   template <typename U>
   ThrowingAllocator& operator=(
       const ThrowingAllocator<U, Flags>& other) noexcept {
@@ -704,11 +711,11 @@ int ThrowingAllocator<T, Throws>::next_id_ = 0;
 // Inspects the constructions and destructions of anything inheriting from
 // TrackedObject.  Place this as a member variable in a test fixture to ensure
 // that every ThrowingValue was constructed and destroyed correctly.  This also
-// allows us to safely "leak" TrackedObjects, as AllocInspector will destroy
+// allows us to safely "leak" TrackedObjects, as ConstructorTracker will destroy
 // everything left over in its destructor.
-struct AllocInspector {
-  AllocInspector() = default;
-  ~AllocInspector() {
+struct ConstructorTracker {
+  ConstructorTracker() = default;
+  ~ConstructorTracker() {
     auto& allocs = exceptions_internal::TrackedObject::GetAllocs();
     for (const auto& kv : allocs) {
       ADD_FAILURE() << "Object at address " << static_cast<void*>(kv.first)
@@ -720,7 +727,7 @@ struct AllocInspector {
 
 // Tests for resource leaks by attempting to construct a T using args repeatedly
 // until successful, using the countdown method.  Side effects can then be
-// tested for resource leaks.  If an AllocInspector is present in the test
+// tested for resource leaks.  If a ConstructorTracker is present in the test
 // fixture, then this will also test that memory resources are not leaked as
 // long as T allocates TrackedObjects.
 template <typename T, typename... Args>