Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing reset when deserializing std::optional if serialized value is empty #335

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/eosiolib/core/eosio/datastream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ inline datastream<Stream>& operator>>(datastream<Stream>& ds, std::optional<T>&
T val;
ds >> val;
opt = val;
}
} else { opt.reset(); }
return ds;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/unit/datastream_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,13 @@ EOSIO_TEST_BEGIN(datastream_stream_test)
ds.seekp(0);
ds >> o;
CHECK_EQUAL( co, o )
// test upacking an empty std::optional to a non-empty works
static const optional<char> co1{}; // empty
ds.seekp(0);
ds << co1;
ds.seekp(0);
ds >> o; // o had value
CHECK_EQUAL( co1, o )

// ---------
// std::pair
Expand Down
Loading