From 703abac9c80f85300e90d51208a2dbba469ccf6d Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Tue, 15 Apr 2025 15:56:58 -0600 Subject: [PATCH] AK: Add const_cast escape hatch for converting const T& to `RefPtr` There are parts of the codebase where properly const-correctifying the the code would be a giant spaghetti mess, so add this loud workaround to defer the refactoring for later. --- AK/RefPtr.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/AK/RefPtr.h b/AK/RefPtr.h index 4276b82b786..ad0199b47f6 100644 --- a/AK/RefPtr.h +++ b/AK/RefPtr.h @@ -312,6 +312,24 @@ inline RefPtr static_ptr_cast(RefPtr const& ptr) return RefPtr(static_cast(ptr.ptr())); } +template +inline NonnullRefPtr fixme_launder_const_through_pointer_cast(NonnullRefPtr const& ptr) +{ + return NonnullRefPtr(const_cast(*ptr)); +} + +template +inline RefPtr fixme_launder_const_through_pointer_cast(RefPtr const& ptr) +{ + return RefPtr(const_cast(ptr.ptr())); +} + +template +inline NonnullRefPtr fixme_launder_const_through_pointer_cast(T const& ptr) +{ + return NonnullRefPtr(const_cast(ptr)); +} + template requires(IsConvertible) inline void swap(RefPtr& a, RefPtr& b)