From 93bb71232da8be4d30b16a3c0a3b5fd596077870 Mon Sep 17 00:00:00 2001
From: Nikita Ofitserov <himikof@gmail.com>
Date: Tue, 25 Jul 2017 12:17:32 +0300
Subject: [PATCH] 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
---
 src/json.hpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/json.hpp b/src/json.hpp
index ab725f55..20c2f618 100644
--- a/src/json.hpp
+++ b/src/json.hpp
@@ -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))