[libcxx-commits] [libcxx] 583c8ce - [libc++] Fix broken test for std::any and allocators

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Sep 15 12:02:02 PDT 2020


Author: Louis Dionne
Date: 2020-09-15T15:01:52-04:00
New Revision: 583c8ce30c12511a814a1db2923b9809f2a15c54

URL: https://github.com/llvm/llvm-project/commit/583c8ce30c12511a814a1db2923b9809f2a15c54
DIFF: https://github.com/llvm/llvm-project/commit/583c8ce30c12511a814a1db2923b9809f2a15c54.diff

LOG: [libc++] Fix broken test for std::any and allocators

The test was not allocating the right number of bytes. This is my fault,
not Marshall's, as I was the one to write the tests for 39c879514170.

Added: 
    

Modified: 
    libcxx/test/libcxx/utilities/any/allocator.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/libcxx/utilities/any/allocator.pass.cpp b/libcxx/test/libcxx/utilities/any/allocator.pass.cpp
index c6800eb832bd..9de8c5e7edff 100644
--- a/libcxx/test/libcxx/utilities/any/allocator.pass.cpp
+++ b/libcxx/test/libcxx/utilities/any/allocator.pass.cpp
@@ -35,10 +35,8 @@ bool Large_was_constructed = false;
 bool Large_was_destroyed = false;
 bool Large_was_deallocated = false;
 
-bool Small_was_allocated = false;
 bool Small_was_constructed = false;
 bool Small_was_destroyed = false;
-bool Small_was_deallocated = false;
 
 namespace std {
   template <>
@@ -51,7 +49,7 @@ namespace std {
 
     Large* allocate(std::size_t n) {
       Large_was_allocated = true;
-      return static_cast<Large*>(::operator new(n));
+      return static_cast<Large*>(::operator new(n * sizeof(Large)));
     }
 
     template <typename ...Args>
@@ -79,10 +77,7 @@ namespace std {
     using propagate_on_container_move_assignment = std::true_type;
     using is_always_equal = std::true_type;
 
-    Small* allocate(std::size_t n) {
-      Small_was_allocated = true;
-      return static_cast<Small*>(::operator new(n));
-    }
+    Small* allocate(std::size_t) { assert(false); }
 
     template <typename ...Args>
     void construct(Small* p, Args&& ...args) {
@@ -95,10 +90,7 @@ namespace std {
       Small_was_destroyed = true;
     }
 
-    void deallocate(Small* p, std::size_t) {
-      Small_was_deallocated = true;
-      return ::operator delete(p);
-    }
+    void deallocate(Small*, std::size_t) { assert(false); }
   };
 } // end namespace std
 
@@ -124,12 +116,10 @@ int main(int, char**) {
       std::any a = Small();
       (void)a;
 
-      assert(!Small_was_allocated);
       assert(Small_was_constructed);
     }
 
     assert(Small_was_destroyed);
-    assert(!Small_was_deallocated);
   }
 
   return 0;


        


More information about the libcxx-commits mailing list