-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<memory>
: Add different control block types for allocate_shared_for_overwrite
#4274
Conversation
<memory>
: Add different control block types for allocator_shared_for_overwrite
<memory>
: Add different control block types for allocate_shared_for_overwrite
Do these control blocks need new visualizers? |
I'm now trying to add visualizer for
Edit: Completed these visualizers. However, it's unfortunate that the control blocks for Test program
#include <memory>
#include <memory_resource>
#include <string>
int main() {
// make_shared for arrays of trivial types
{
auto p = std::make_shared<int[8]>();
p[1] = 42;
}
{
auto p = std::make_shared<int[]>(8);
p[1] = 42;
}
{
auto p = std::make_shared_for_overwrite<int[8]>();
p[1] = 42;
}
{
auto p = std::make_shared_for_overwrite<int[]>(8);
p[1] = 42;
}
// make_shared for arrays of non-trivial types
{
auto p = std::make_shared<std::string[8]>("s");
p[1] = "42";
}
{
auto p = std::make_shared<std::string[]>(8, "s");
p[1] = "42";
}
{
auto p = std::make_shared_for_overwrite<std::string[8]>();
p[1] = "42";
}
{
auto p = std::make_shared_for_overwrite<std::string[]>(8);
p[1] = "42";
}
// allocate_shared(_for_overwrite)
{
auto p = std::allocate_shared<int[8]>(std::allocator<int>{});
p[1] = 42;
auto q = std::allocate_shared<int[8]>(std::pmr::polymorphic_allocator<int>{});
q[2] = -42;
}
{
auto p = std::allocate_shared<int[]>(std::allocator<int>{}, 8);
p[1] = 42;
auto q = std::allocate_shared<int[]>(std::pmr::polymorphic_allocator<int>{}, 8);
q[2] = -42;
}
{
auto p = std::allocate_shared_for_overwrite<int>(std::allocator<int>{});
*p = 42;
auto q = std::allocate_shared_for_overwrite<int>(std::pmr::polymorphic_allocator<int>{});
*q = -42;
}
{
auto p = std::allocate_shared_for_overwrite<int[8]>(std::allocator<int>{});
p[1] = 42;
auto q = std::allocate_shared_for_overwrite<int[8]>(std::pmr::polymorphic_allocator<int>{});
q[2] = -42;
}
{
auto p = std::allocate_shared_for_overwrite<int[]>(std::allocator<int>{}, 8);
p[1] = 42;
auto q = std::allocate_shared_for_overwrite<int[]>(std::pmr::polymorphic_allocator<int>{}, 8);
q[2] = -42;
}
} |
Thanks! 😻 This investigation, fix, and visualizers must have been a lot of work, I really appreciate it. I pushed a couple of tiny commits and I think this is ready to go. |
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Thanks for destroying this bug! 🐞 💥 😹 |
allocate_shared_for_overwrite
creates allocated non-array objects by default-initialization, so these objects should be destroyed by plain destructor calls, notAtor::destroy
. Currently the standard wording is unclear onmake_shared_for_overwrite
andallocate_shared_for_overwrite
, so I submitted LWG-4024.It's a bit unfortunate that the existing control block types can't be reused because the
_Destroy
functions can't recognize_For_overwrite_tag
.Unblocks one libcxx test:
std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_for_overwrite.pass.cpp
Drive-by changes: