mirror of
https://github.com/nlohmann/json.git
synced 2024-11-28 00:59:02 +08:00
Move from rvalues eagerly to work around MSVC problem
On MSVC compiler, temporaries that are constructed during a list initialization, are sometimes destroyed even before calling the initializing constructor, instead of at the end of the containing full-expression. This is clearly non-conforming to [class.temporary]. As the impact of this bug is silently producing incorrect JSON values, move eagerly from rvalues to be safe. See https://stackoverflow.com/questions/24586411
This commit is contained in:
parent
897879bccb
commit
93bb71232d
@ -7088,9 +7088,11 @@ struct json_ref
|
||||
typedef BasicJsonType value_type;
|
||||
|
||||
json_ref(value_type&& value)
|
||||
: value_ref_(&value)
|
||||
: owned_value_(std::move(value))
|
||||
, is_rvalue_(true)
|
||||
{}
|
||||
{
|
||||
value_ref_ = &owned_value_;
|
||||
}
|
||||
|
||||
json_ref(const value_type& value)
|
||||
: value_ref_(const_cast<value_type*>(&value))
|
||||
|
Loading…
Reference in New Issue
Block a user