[libc-commits] [libc] [libc] Implement CheckedPtr utility (PR #234646)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Fri Oct 23 03:24:10 PDT 2026


kaladron wrote:

Could we add tests in checked_ptr_test.cpp for the following cases?

* Dereferencing a checked-but-null CheckedPtr (death tests): Checking a null CheckedPtr via operator bool() (e.g., if (!ptr) where the caller forgets an early return) marks it as checked while the underlying pointer is still nullptr. We should assert non-nullness in operator*, operator->, and operator[] and add death tests verifying that dereferencing a checked nullptr dies.
* Dereferencing after take_unique() (death tests): take_unique() leaves the CheckedPtr in the checked state (so its destructor won't assert) while moving out the underlying pointer. We should test that subsequent calls to *ptr, ptr->, or ptr[i] die.
* Dereferencing a moved-from CheckedPtr (death test): Moving from a CheckedPtr disarms its destructor by marking it checked while leaving the underlying pointer null. We should test that dereferencing a moved-from CheckedPtr dies.
* Move-assigning into an already-checked CheckedPtr resets its checked state (death test): We test that move-constructing from a checked pointer requires re-checking the destination, but we don't have a death test verifying that move-assigning into an already-checked CheckedPtr resets it to unchecked and dies if dereferenced without re-checking.
* Converting move-assignment (CheckedPtr<Base>::operator=(CheckedPtr<Derived> &&)): Conversions currently only tests the converting move constructor, leaving the converting move-assignment operator template uninstantiated.
* Lvalue custom deleter constructor (CheckedPtr(pointer, const deleter_type &)): CustomDeleters only passes an rvalue deleter temporary, leaving the const deleter_type & constructor overload uninstantiated.
* Compile-time rejection of known-bound arrays (make_unique<T[N]>): A static_assert verifying that make_unique<int[3]> is rejected by SFINAE.

https://github.com/llvm/llvm-project/pull/234646


More information about the libc-commits mailing list