diff --git a/include/rfl/internal/to_ptr_field.hpp b/include/rfl/internal/to_ptr_field.hpp index 6468d5e4..4570e9fb 100644 --- a/include/rfl/internal/to_ptr_field.hpp +++ b/include/rfl/internal/to_ptr_field.hpp @@ -5,6 +5,7 @@ #include "rfl/Field.hpp" #include "rfl/Flatten.hpp" +#include "rfl/always_false.hpp" #include "rfl/internal/StringLiteral.hpp" namespace rfl { @@ -12,18 +13,39 @@ namespace internal { template inline auto to_ptr_field(Field<_name, Type>& _field) { + if constexpr (std::is_pointer_v) { + static_assert(always_false_v, + "Writing from raw pointers is dangerous and " + "therefore unsupported. " + "Please consider using std::unique_ptr, rfl::Box, " + "std::shared_ptr, rfl::Ref or std::optional instead."); + } using T = std::remove_reference_t; return Field<_name, T*>(&_field.value_); } template inline auto to_ptr_field(const Field<_name, Type>& _field) { + if constexpr (std::is_pointer_v) { + static_assert(always_false_v, + "Writing from raw pointers is dangerous and " + "therefore unsupported. " + "Please consider using std::unique_ptr, rfl::Box, " + "std::shared_ptr, rfl::Ref or std::optional instead."); + } using T = std::remove_cvref_t; return Field<_name, const T*>(&_field.value_); } template inline auto to_ptr_field(Flatten& _field) { + if constexpr (std::is_pointer_v) { + static_assert(always_false_v, + "Writing from raw pointers is dangerous and " + "therefore unsupported. " + "Please consider using std::unique_ptr, rfl::Box, " + "std::shared_ptr, rfl::Ref or std::optional instead."); + } using T = std::remove_reference_t; return Flatten(&_field.value_); }