diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 4e66214cc..56b8eca61 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -167,10 +167,14 @@ class meta_any { template [[nodiscard]] static meta_any dereference_operator(meta_any &any) { if constexpr(is_meta_pointer_like_v) { - if constexpr(std::is_const_v())>>) { - return *any.cast(); - } else { + using pointed_type = std::remove_reference_t())>; + + if constexpr(std::is_const_v && std::is_copy_constructible_v) { + return std::as_const(*any.cast()); + } else if constexpr(!std::is_const_v) { return std::ref(*any.cast()); + } else { + return {}; } } else { return {}; diff --git a/test/entt/meta/meta_any.cpp b/test/entt/meta/meta_any.cpp index fb9750d4f..958884ceb 100644 --- a/test/entt/meta/meta_any.cpp +++ b/test/entt/meta/meta_any.cpp @@ -5,7 +5,6 @@ #include #include - struct clazz_t { void member(int i) { value = i; } static void func() { c = 'd'; } diff --git a/test/entt/meta/meta_pointer.cpp b/test/entt/meta/meta_pointer.cpp index 8280a0109..1c5052f39 100644 --- a/test/entt/meta/meta_pointer.cpp +++ b/test/entt/meta/meta_pointer.cpp @@ -4,6 +4,14 @@ #include #include +struct not_copyable_t { + not_copyable_t() = default; + not_copyable_t(const not_copyable_t &) = delete; + not_copyable_t(not_copyable_t &&) = default; + not_copyable_t & operator=(const not_copyable_t &) = delete; + not_copyable_t & operator=(not_copyable_t &&) = default; +}; + TEST(MetaPointerLike, DereferenceOperatorInvalidType) { int value = 0; entt::meta_any any{value}; @@ -79,3 +87,11 @@ TEST(MetaPointerLike, DereferenceOperatorSmartPointer) { ASSERT_EQ(*any.cast>(), 42); ASSERT_EQ(*value, 42); } + +TEST(MetaPointerLike, PointerToMoveOnlyType) { + const not_copyable_t instance; + entt::meta_any any{&instance}; + + ASSERT_TRUE(any); + ASSERT_FALSE(*any); +} \ No newline at end of file