meta: try to please all compilers (as usual)

This commit is contained in:
Michele Caini
2022-07-06 11:52:32 +02:00
parent df48cc9471
commit 669420d31c
3 changed files with 12 additions and 5 deletions

View File

@@ -1237,12 +1237,12 @@ public:
* @return A wrapper that references the given instance.
*/
meta_any from_void(void *element) {
return node->from_void ? node->from_void(element, nullptr) : meta_any{};
return (element && node->from_void) ? node->from_void(element, nullptr) : meta_any{};
}
/*! @copydoc from_void */
meta_any from_void(const void *element) {
return node->from_void ? node->from_void(nullptr, element) : meta_any{};
return (element && node->from_void) ? node->from_void(nullptr, element) : meta_any{};
}
/**

View File

@@ -155,7 +155,11 @@ class ENTT_API meta_node {
return static_cast<std::decay_t<decltype(meta_type_node::from_void)>>(nullptr);
} else {
return +[](void *element, const void *as_const) {
return element ? meta_any{std::in_place_type<Type &>, *static_cast<Type *>(element)} : meta_any{std::in_place_type<const Type &>, *static_cast<const Type *>(as_const)};
if (element) {
return meta_any{std::in_place_type<Type &>, *static_cast<Type *>(element)};
}
return meta_any{std::in_place_type<const Type &>, *static_cast<const Type *>(as_const)};
};
}
}

View File

@@ -468,12 +468,15 @@ TEST_F(MetaType, ConstructArithmeticConversion) {
TEST_F(MetaType, FromVoid) {
using namespace entt::literals;
ASSERT_FALSE(entt::resolve<void>().from_void(static_cast<void *>(nullptr)));
ASSERT_FALSE(entt::resolve<void>().from_void(static_cast<const void *>(nullptr)));
ASSERT_FALSE(entt::resolve<double>().from_void(static_cast<double *>(nullptr)));
ASSERT_FALSE(entt::resolve<double>().from_void(static_cast<const double *>(nullptr)));
auto type = entt::resolve<double>();
double value = 4.2;
ASSERT_FALSE(entt::resolve<void>().from_void(static_cast<void *>(&value)));
ASSERT_FALSE(entt::resolve<void>().from_void(static_cast<const void *>(&value)));
auto as_void = type.from_void(static_cast<void *>(&value));
auto as_const_void = type.from_void(static_cast<const void *>(&value));