[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 39c8795141.
This commit is contained in:
Louis Dionne 2020-09-15 14:59:27 -04:00
parent 558e5c31b6
commit 583c8ce30c
1 changed files with 3 additions and 13 deletions

View File

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