1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:17:44 +00:00

AK: Delete bad pointer assignment operators and constructors.

We shouldn't allow constructing e.g an OwnPtr from a RefPtr, and similar
conversions. Instead just delete those functions so the compiler whines
loudly if you try to use them.

This patch also deletes constructing OwnPtr from a WeakPtr, even though
that *may* be a valid thing to do, it's sufficiently weird that we can
make the client jump through some hoops if he really wants it. :^)
This commit is contained in:
Andreas Kling 2019-07-11 16:43:20 +02:00
parent 01998a10e3
commit 25e3d46502
3 changed files with 36 additions and 0 deletions

View file

@ -7,6 +7,13 @@
namespace AK {
template<typename T>
class RefPtr;
template<typename T>
class NonnullRefPtr;
template<typename T>
class WeakPtr;
template<typename T>
class OwnPtr {
public:
@ -36,6 +43,19 @@ public:
#endif
}
template<typename U>
OwnPtr(const RefPtr<U>&) = delete;
template<typename U>
OwnPtr(const NonnullRefPtr<U>&) = delete;
template<typename U>
OwnPtr(const WeakPtr<U>&) = delete;
template<typename U>
OwnPtr& operator=(const RefPtr<U>&) = delete;
template<typename U>
OwnPtr& operator=(const NonnullRefPtr<U>&) = delete;
template<typename U>
OwnPtr& operator=(const WeakPtr<U>&) = delete;
OwnPtr& operator=(OwnPtr&& other)
{
if (this != &other) {