Skip to content

Commit 38832d9

Browse files
drewdzzzalyapunov
authored andcommitted
Dec: unwrap member pointer in detectFamily
It is required to correctly build JumpTable for classes with custom decoding rule - we need to get the underlying type to understand what types are acceptable to decode.
1 parent b481eeb commit 38832d9

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/mpp/Dec.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,12 @@ template <class BUF, class T>
102102
constexpr auto detectFamily()
103103
{
104104
using U = unwrap_t<T>;
105-
static_assert(!std::is_const_v<U> || tnt::is_tuplish_v<U>,
105+
static_assert(!std::is_const_v<U> || tnt::is_tuplish_v<U> ||
106+
std::is_member_pointer_v<U>,
106107
"Can't decode to constant type");
107-
if constexpr (is_raw_decoded_v<T, BUF>) {
108+
if constexpr (std::is_member_pointer_v<U>) {
109+
return detectFamily<BUF, tnt::demember_t<U>>();
110+
} else if constexpr (is_raw_decoded_v<T, BUF>) {
108111
static_assert(!is_wrapped_family_v<T>);
109112
return getFamiliesByRules<all_rules_t>();
110113
} else if constexpr (is_wrapped_family_v<T>) {

test/EncDecTest.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,18 @@ test_optional()
13501350

13511351
buf.flush();
13521352

1353+
TEST_CASE("trivial object");
1354+
mpp::encode(buf, std::optional<IntegerWrapper>({64}));
1355+
1356+
run = buf.begin<true>();
1357+
std::optional<IntegerWrapper> opt_int_wrapper;
1358+
ok = mpp::decode(run, opt_int_wrapper);
1359+
fail_unless(ok);
1360+
fail_unless(opt_int_wrapper.has_value());
1361+
fail_unless(opt_int_wrapper.value().i == 64);
1362+
1363+
buf.flush();
1364+
13531365
TEST_CASE("objects");
13541366
Body wr;
13551367
wr.gen();

0 commit comments

Comments
 (0)