Description
Variables of type std::unique_ptr<some_t> are correctly shown during a debug.
Variables of type std::unique_ptr<some_t, some_deleter> appear as containing a wrong value.
Example
#include <iostream> #include <memory> // The most basic deleter template <typename Allocator> struct deleter { Allocator allocator; deleter() : allocator() { } deleter(Allocator& allocator) : allocator(allocator) { } void operator()(typename std::allocator_traits<Allocator>::value_type* ptr) { std::allocator_traits<Allocator>::destroy(allocator, ptr); std::allocator_traits<Allocator>::deallocate(allocator, ptr, 1); } }; // A function that allocates and constructrs (using args) a value and returns a unique_ptr pointing to template <typename Allocator, typename... Args> std::unique_ptr<typename std::allocator_traits<Allocator>::value_type, deleter<Allocator>> allocate(Allocator& allocator, Args&&... args) { auto* ptr = std::allocator_traits<Allocator>::allocate(allocator, 1); std::allocator_traits<Allocator>::construct(allocator, ptr, std::forward<Args>(args)...); return {ptr, deleter(allocator)}; } int main() { std::allocator<int> al; std::unique_ptr<int> a(allocate(al, 123456).release()); // Case 1 std::unique_ptr<int, deleter<std::allocator<int>>> b(allocate(al, 123456).release()); // Case 2 std::cout << "a: " << *a << std::endl; std::cout << "b: " << *b << std::endl; return 0; }
Both a and b point to the same integer value, output is
a: 123456 b: 123456
However, if we try to debug this simple program, we see b as not accessible