diff --git a/include/msg/field.hpp b/include/msg/field.hpp index d8c7011d..d67b6f6f 100644 --- a/include/msg/field.hpp +++ b/include/msg/field.hpp @@ -362,28 +362,30 @@ template constexpr inline auto field_size = (0u + ... + Ats.size()); template struct with_default { constexpr static auto default_value = V; - template using default_matcher_t = msg::equal_to_t; using is_mutable_t = void; template constexpr static auto is_compatible_value = true; }; template struct with_const_default { constexpr static auto default_value = V; - template using default_matcher_t = msg::equal_to_t; template constexpr static auto is_compatible_value = X == V; }; struct without_default { - template using default_matcher_t = match::never_t; using is_mutable_t = void; template constexpr static auto is_compatible_value = true; }; +struct uninitialized { + template constexpr static auto is_compatible_value = true; +}; + template concept has_default_value = requires { T::default_value; }; template -using has_default_value_t = std::bool_constant>; +using initializable_t = std::bool_constant or + std::is_base_of_v>; template concept is_mutable_value = requires { typename T::is_mutable_t; }; @@ -489,6 +491,8 @@ class field_t : public field_spec_t>, using without_default = field_t; + using uninitialized = field_t; + // ====================================================================== // matcher values template diff --git a/include/msg/message.hpp b/include/msg/message.hpp index 5e59b757..a6c04360 100644 --- a/include/msg/message.hpp +++ b/include/msg/message.hpp @@ -497,7 +497,7 @@ struct message { constexpr owner_t() { using uninit_fields = boost::mp11::mp_remove_if, - has_default_value_t>; + initializable_t>; static_assert(boost::mp11::mp_empty::value, "All fields must be initialized or defaulted"); this->set(Fields{}...); @@ -507,7 +507,7 @@ struct message { using defaulted_fields = boost::mp11::mp_transform< name_for, boost::mp11::mp_copy_if, - has_default_value_t>>; + initializable_t>>; using initialized_fields = boost::mp11::mp_transform>; diff --git a/test/msg/message.cpp b/test/msg/message.cpp index 35c2192c..929ba563 100644 --- a/test/msg/message.cpp +++ b/test/msg/message.cpp @@ -824,3 +824,19 @@ TEST_CASE("write indexing operator on message", "[message]") { CHECK((0xba11 == msg["f1"_field])); } #endif + +namespace { +using bit_field1 = + field<"f1", + std::uint32_t>::located::with_required<1>; +using all_fields = + field<"all", std::uint32_t>::located; + +using overlap_msg_defn = message<"msg", bit_field1, all_fields::uninitialized>; +} // namespace + +TEST_CASE("message with uninitialized field", "[message]") { + owning msg{}; + auto data = msg.data(); + CHECK(data[0] == 1); +}