[libcxx-commits] [libcxx] [libc++] Correctly handle custom deleters in hardened unique_ptr<T[]> (PR #110685)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Oct 1 08:19:57 PDT 2024
================
@@ -112,12 +117,33 @@ TEST_CONSTEXPR_CXX23 bool test() {
WithNonTrivialDtor<16>,
WithNonTrivialDtor<256>>;
types::for_each(TrickyCookieTypes(), []<class T> {
- types::for_each(types::type_list<std::default_delete<T[]>, CustomDeleter<T[]>>(), []<class Deleter> {
- std::unique_ptr<T[], Deleter> p(new T[3]);
+ // Array allocated with `new T[n]`, default deleter
+ {
+ std::unique_ptr<T[], std::default_delete<T[]>> p(new T[3]);
+ assert(p[0] == T());
+ assert(p[1] == T());
+ assert(p[2] == T());
+ }
+
+ // Array allocated with `new T[n]`, custom deleter
+ {
+ std::unique_ptr<T[], CustomDeleter<T[]>> p(new T[3]);
+ assert(p[0] == T());
+ assert(p[1] == T());
+ assert(p[2] == T());
+ }
+
+ // Array not allocated with `new T[n]`, custom deleter
+ //
+ // This test aims to ensure that the implementation doesn't try to use an array cookie
+ // when there is none.
+ {
+ T array[50] = {};
----------------
ldionne wrote:
@nico I verified locally and this test breaks down without my patch. That's a smaller version of your reproducer.
https://github.com/llvm/llvm-project/pull/110685
More information about the libcxx-commits
mailing list