Преглед изворни кода

meta: fix constness detection for static functions in meta_type::invoke

Michele Caini пре 3 година
родитељ
комит
1eab2a4a80
2 измењених фајлова са 5 додато и 2 уклоњено
  1. 1 1
      src/entt/meta/meta.hpp
  2. 4 1
      test/entt/meta/meta_type.cpp

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

@@ -1389,7 +1389,7 @@ public:
     meta_any invoke(const id_type id, meta_handle instance, meta_any *const args, const size_type sz) const {
     meta_any invoke(const id_type id, meta_handle instance, meta_any *const args, const size_type sz) const {
         if(node.details) {
         if(node.details) {
             if(auto it = node.details->func.find(id); it != node.details->func.cend()) {
             if(auto it = node.details->func.find(id); it != node.details->func.cend()) {
-                if(const auto *candidate = lookup(args, sz, (instance->data() == nullptr), [curr = &it->second]() mutable { return curr ? std::exchange(curr, curr->next.get()) : nullptr; }); candidate) {
+                if(const auto *candidate = lookup(args, sz, instance && (instance->data() == nullptr), [curr = &it->second]() mutable { return curr ? std::exchange(curr, curr->next.get()) : nullptr; }); candidate) {
                     return candidate->invoke(*ctx, meta_handle{*ctx, std::move(instance)}, args);
                     return candidate->invoke(*ctx, meta_handle{*ctx, std::move(instance)}, args);
                 }
                 }
             }
             }

+ 4 - 1
test/entt/meta/meta_type.cpp

@@ -378,7 +378,10 @@ TEST_F(MetaType, Invoke) {
     clazz_t instance{};
     clazz_t instance{};
 
 
     ASSERT_TRUE(type.invoke("member"_hs, instance));
     ASSERT_TRUE(type.invoke("member"_hs, instance));
-    ASSERT_FALSE(type.invoke("rebmem"_hs, {}));
+    ASSERT_FALSE(type.invoke("rebmem"_hs, instance));
+
+    ASSERT_TRUE(type.invoke("func"_hs, {}));
+    ASSERT_FALSE(type.invoke("cnuf"_hs, {}));
 }
 }
 
 
 TEST_F(MetaType, InvokeFromBase) {
 TEST_F(MetaType, InvokeFromBase) {