cpp11::preserved relies on the list_ data member having a well-defined value at the time preserved is accessed. Since the order of construction of globals is not guaranteed in c++, that can lead to undefined behavior if you're constructing (for example) a global cpp11::strings since that appends to preserved in the constructor.
namespace {
// the value of `cpp11::preserved.list_` is not guaranteed here!
cpp11::strings kColorStrings = cpp11::writable::strings({
"red",
"green",
"blue",
});
} // namespace
cpp11::preserved
relies on thelist_
data member having a well-defined value at the timepreserved
is accessed. Since the order of construction of globals is not guaranteed in c++, that can lead to undefined behavior if you're constructing (for example) a globalcpp11::strings
since that appends topreserved
in the constructor.