I found a strange behavior when using std::unique_ptr with arrays, please see:
{
auto v = std::make_unique<unsigned char []>(10);
assert(v);
std::cout << std::hex << v.get() << std::endl; // does not print anything
}
{
auto v = std::make_unique<char []>(10);
assert(v);
std::cout << v.get() << std::endl; // does not print anything
}
{
auto v = std::make_unique<uint8_t []>(10);
assert(v);
std::cout << v.get() << std::endl; // does not print anything
}
{
auto v = std::make_unique<std::array<uint8_t, 10>>();
assert(v);
std::cout << v.get() << std::endl; // works, prints address
}
{
auto v = std::make_unique<uint16_t []>(10);
assert(v);
std::cout << v.get() << std::endl; // works, prints address
}
What's the reason why it doesn't work for byte size arrays? Am I missing something trivial? The above behavior is consistent for C++14 Clang 3.8, gcc 4.9 and 5.2. I read the C++ standard and didn't find something relevant, it would be nice to have an answer that addresses this behavior.