summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
Diffstat (limited to 'compat')
-rw-r--r--compat/borrowed-ptr-fwd.hpp2
-rw-r--r--compat/borrowed-ptr.hpp13
2 files changed, 9 insertions, 6 deletions
diff --git a/compat/borrowed-ptr-fwd.hpp b/compat/borrowed-ptr-fwd.hpp
index da91502d..465e9bf4 100644
--- a/compat/borrowed-ptr-fwd.hpp
+++ b/compat/borrowed-ptr-fwd.hpp
@@ -44,7 +44,7 @@ public:
T& operator*() const noexcept;
template<typename U> friend class bptr;
- template<typename Tʹ, typename U> friend bptr<U> static_pointer_cast(const bptr<Tʹ>& p) noexcept;
+ template<typename U, typename Tʹ> friend bptr<U> static_pointer_cast(const bptr<Tʹ>& p) noexcept;
};
} // namespace floormat
diff --git a/compat/borrowed-ptr.hpp b/compat/borrowed-ptr.hpp
index 5caa2261..d13d8ee2 100644
--- a/compat/borrowed-ptr.hpp
+++ b/compat/borrowed-ptr.hpp
@@ -28,20 +28,23 @@ concept StaticCastable = requires(From* from) {
namespace floormat {
-template<typename T, typename U>
+template<typename U, typename T>
bptr<U> static_pointer_cast(const bptr<T>& p) noexcept
{
- static_assert(detail_borrowed_ptr::StaticCastable<T, U>);
-
- if (p.blk) [[likely]]
+ // hack to generate better error message
+ if constexpr (detail_borrowed_ptr::StaticCastable<T, U>)
{
- if (auto* ptr = p.blk->_ptr)
+ if (p.blk && p.blk->_ptr) [[likely]]
{
fm_bptr_assert(p.casted_ptr);
auto* ret = static_cast<U*>(p.casted_ptr);
return bptr<U>{DirectInit, ret, p.blk};
}
}
+ else
+ // concepts can't be forward-declared so use static_assert
+ static_assert(detail_borrowed_ptr::StaticCastable<T, U>);
+
return bptr<U>{nullptr};
}