Browse Source

meta_any: avoid dereferencing C-style arrays

Michele Caini 4 years ago
parent
commit
b0069299ea
2 changed files with 12 additions and 1 deletions
  1. 1 1
      src/entt/meta/meta.hpp
  2. 11 0
      test/entt/meta/meta_pointer.cpp

+ 1 - 1
src/entt/meta/meta.hpp

@@ -177,7 +177,7 @@ class meta_any {
                 break;
             case operation::DEREF:
             case operation::CDEREF:
-                if constexpr(is_meta_pointer_like_v<std::decay_t<Type>>) {
+                if constexpr(is_meta_pointer_like_v<std::remove_const_t<std::remove_reference_t<Type>>>) {
                     using element_type = std::remove_const_t<typename std::pointer_traits<std::decay_t<Type>>::element_type>;
 
                     if constexpr(std::is_function_v<element_type>) {

+ 11 - 0
test/entt/meta/meta_pointer.cpp

@@ -333,3 +333,14 @@ TEST(MetaPointerLike, DereferenceProxyPointer) {
 
     ASSERT_EQ(value, 42);
 }
+
+TEST(MetaPointerLike, DereferenceArray) {
+    entt::meta_any array{std::in_place_type<int[3]>};
+    entt::meta_any array_of_array{std::in_place_type<int[3][3]>};
+
+    ASSERT_EQ(array.type(), entt::resolve<int[3]>());
+    ASSERT_EQ(array_of_array.type(), entt::resolve<int[3][3]>());
+
+    ASSERT_FALSE(*array);
+    ASSERT_FALSE(*array_of_array);
+}