瀏覽代碼

LibJS: Temporarily disambiguate const-ness of GCPtr constructors

Without this change, using {Nonnull,}GCPtr<T const> would complain that
there are multiple constructors which resolve to the same type (T& and
T const&). This removes that disambiguation and allows us to slowly fix
all of the constness issues surrounding GCPtrs. This change will not be
necessary in the future as we will be able to remove all of the const
qualifiers from the Ptr classes (they'll be in the template type
instead).
Matthew Olsson 2 年之前
父節點
當前提交
17a528c49e
共有 1 個文件被更改,包括 4 次插入1 次删除
  1. 4 1
      Userland/Libraries/LibJS/Heap/GCPtr.h

+ 4 - 1
Userland/Libraries/LibJS/Heap/GCPtr.h

@@ -24,6 +24,7 @@ public:
     }
     }
 
 
     NonnullGCPtr(T const& ptr)
     NonnullGCPtr(T const& ptr)
+    requires(!IsConst<T>)
         : m_ptr(&const_cast<T&>(ptr))
         : m_ptr(&const_cast<T&>(ptr))
     {
     {
     }
     }
@@ -37,7 +38,7 @@ public:
 
 
     template<typename U>
     template<typename U>
     NonnullGCPtr(U const& ptr)
     NonnullGCPtr(U const& ptr)
-    requires(IsConvertible<U*, T*>)
+    requires(IsConvertible<U*, T*> && !IsConst<T>)
         : m_ptr(&const_cast<T&>(static_cast<T const&>(ptr)))
         : m_ptr(&const_cast<T&>(static_cast<T const&>(ptr)))
     {
     {
     }
     }
@@ -96,6 +97,7 @@ public:
     }
     }
 
 
     GCPtr(T const& ptr)
     GCPtr(T const& ptr)
+    requires(!IsConst<T>)
         : m_ptr(&const_cast<T&>(ptr))
         : m_ptr(&const_cast<T&>(ptr))
     {
     {
     }
     }
@@ -106,6 +108,7 @@ public:
     }
     }
 
 
     GCPtr(T const* ptr)
     GCPtr(T const* ptr)
+    requires(!IsConst<T>)
         : m_ptr(const_cast<T*>(ptr))
         : m_ptr(const_cast<T*>(ptr))
     {
     {
     }
     }