1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:37:34 +00:00

LibJS+LibWeb: Apply the Rule of Zero to {Nonnull,}GCPtr<T>

The compiler-generated copy constructor and copy assignment operator
already do the right thing (which is to simply copy the underlying
pointer).

The [Itanium C++ ABI][1] treats any class with non-trivial copy/move
constructors and destructors as non-trivial for the purposes of calls --
even if they are functionally identical to the compiler-generated ones.
If a class is non-trivial, it cannot be passed or returned in registers,
only via an invisible reference, which is worse for codegen. This commit
makes `{Nonnull,}GCPtr` trivial.

As the compiler can be sure that capturing a `GCPtr` by value has no
side effects, a few `-Wunused-lambda-capture` warnings had to be
addressed in LibWeb.

GCC seems to have a bug that prevents `ExceptionOr<Variant<GCPtr<T>>>`
from being implicitly constructed from `GCPtr<T>` after this change. A
non-invasive workaround is to explicitly construct the inner Variant
type.

[1]: https://itanium-cxx-abi.github.io/cxx-abi/abi.html#non-trivial
This commit is contained in:
Daniel Bertalan 2023-07-26 19:02:37 +02:00 committed by Tim Flynn
parent 82495083c3
commit 9feb1ce39f
4 changed files with 8 additions and 26 deletions

View file

@ -31,11 +31,6 @@ public:
{
}
NonnullGCPtr(NonnullGCPtr const& other)
: m_ptr(other.ptr())
{
}
template<typename U>
NonnullGCPtr(NonnullGCPtr<U> const& other)
requires(IsConvertible<U*, T*>)
@ -43,12 +38,6 @@ public:
{
}
NonnullGCPtr& operator=(NonnullGCPtr const& other)
{
m_ptr = other.ptr();
return *this;
}
template<typename U>
NonnullGCPtr& operator=(NonnullGCPtr<U> const& other)
requires(IsConvertible<U*, T*>)
@ -88,7 +77,7 @@ private:
template<typename T>
class GCPtr {
public:
GCPtr() = default;
constexpr GCPtr() = default;
GCPtr(T& ptr)
: m_ptr(&ptr)
@ -100,11 +89,6 @@ public:
{
}
GCPtr(GCPtr<T> const& other)
: m_ptr(other.ptr())
{
}
template<typename U>
GCPtr(GCPtr<U> const& other)
requires(IsConvertible<U*, T*>)
@ -129,8 +113,6 @@ public:
{
}
GCPtr& operator=(GCPtr const&) = default;
template<typename U>
GCPtr& operator=(GCPtr<U> const& other)
requires(IsConvertible<U*, T*>)