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

any: detect C-style arrays and use delete[] when needed

Michele Caini пре 5 година
родитељ
комит
505cfdd193
1 измењених фајлова са 5 додато и 1 уклоњено
  1. 5 1
      src/entt/core/any.hpp

+ 5 - 1
src/entt/core/any.hpp

@@ -115,7 +115,11 @@ class any {
                     as<any>(to).instance = from.instance;
                     break;
                 case operation::DTOR:
-                    delete static_cast<const Type *>(from.instance);
+                    if constexpr(std::is_array_v<Type>) {
+                        delete[] static_cast<const Type *>(from.instance);
+                    } else {
+                        delete static_cast<const Type *>(from.instance);
+                    }
                     break;
                 case operation::COMP:
                     return compare<Type>(from.instance, to) ? to : nullptr;