Add missing pointer deletion in AutoPtr move assignment operator#9005
Add missing pointer deletion in AutoPtr move assignment operator#9005Noremos wants to merge 2 commits intoFirebirdSQL:masterfrom
Conversation
|
Move assignment can be implemented more simply: AutoPtr& operator=(AutoPtr&& r) noexcept
{
std::swap(ptr, r.ptr);
return *this;
}In this case, you don't need to call any cleanup functions. The destructor of the moved object will do the cleanup. You can also safely remove the self-assignment check. |
|
Is self-swap a defined behavior? I don't see mention of it on https://en.cppreference.com/cpp/algorithm/swap The problem may be that lifetime of the old content become unpredictable in common case. Moving from global static object will let it live forever that may be unexpected. Of course, in most cases the target pointer is empty, that's why this code lived for years unnoticed. |
For trivial types, which pointers are, yes.
Do you seriously think that global static objects will be wrapped in |
The real reason is that this code never used. |
Don't replace move assigment by swap. This is different things for different purposes. |
I use this in my JSON implementation. And that's how I found the bug. |
No description provided.