This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
Document how to properly use multi_index::get
and deprecate related methods that take a reference
#818
Labels
documentation
Documentation related edits, non-breaking only
We need clear documentation on how to use
multi_index::get
so that contract developers avoid the common pitfall of copy assigning the reference returned frommulti_index::get
to a stack-allocated local variable and then passing that intomulti_index::modify
.The most common mistake is that users use
auto
as the typename for the local variable when they should be usingauto&
ordecltype(auto)
.Also, because this is a common mistake contract developers make which could lead to undefined behavior, we should deprecate the overloads of
modify
anderase
methods inmulti_index
that take a reference, and encourage them to use the versions that takeconst_iterator
instead which are much safer.We should also provide warnings in the documentation about using
iterator_to
which can have similar undefined behavior if the developer passes in a reference to a stack-allocated object rather than the reference returned byget
or by dereferencing aconst_iterator
. Perhaps we can also provide a safer overload ofiterator_to
that takes aconst_iterator
.Along with deprecating
multi_index::get
, we should also make sure we do not actually use it in any of the contracts in our repository. Instead we could usemulti_index::require_find
from EOSIO/eos#4227.The text was updated successfully, but these errors were encountered: