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:
Nikita Ofitserov 2017-07-25 12:17:32 +03:00
parent 897879bccb
commit 93bb71232d

View File

@ -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))