From 4b46abf97ce3532b5cbff8b68a026cfb76cc9be9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Th=C3=A9o=20DELRIEU?= <delrieutheo@gmail.com>
Date: Sat, 28 Oct 2017 14:22:57 +0200
Subject: [PATCH] add forwarding references to json_ref constructor

fixes #805
---
 src/json.hpp                 |  2 +-
 test/src/unit-regression.cpp | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/json.hpp b/src/json.hpp
index 5c6515bf..e8941302 100644
--- a/src/json.hpp
+++ b/src/json.hpp
@@ -6789,7 +6789,7 @@ class json_ref
     {}
 
     template <class... Args>
-    json_ref(Args... args)
+    json_ref(Args&&... args)
         : owned_value(std::forward<Args>(args)...),
           value_ref(&owned_value),
           is_rvalue(true)
diff --git a/test/src/unit-regression.cpp b/test/src/unit-regression.cpp
index 1e1588e6..edd03b9c 100644
--- a/test/src/unit-regression.cpp
+++ b/test/src/unit-regression.cpp
@@ -36,6 +36,22 @@ using nlohmann::json;
 #include <list>
 #include <cstdio>
 
+namespace
+{
+  struct nocopy
+  {
+    nocopy() = default;
+    nocopy(const nocopy &) = delete;
+
+    int val = 0;
+
+    friend void to_json(json& j, const nocopy& n)
+    {
+      j = {{"val", n.val}};
+    }
+  };
+}
+
 TEST_CASE("regression tests")
 {
     SECTION("issue #60 - Double quotation mark is not parsed correctly")
@@ -1282,4 +1298,12 @@ TEST_CASE("regression tests")
             }
         }
     */
+
+    SECTION("issue #805 - copy constructor is used with std::initializer_list constructor.")
+    {
+      nocopy n;
+      json j;
+      j = {{"nocopy", n}};
+      CHECK(j["nocopy"]["val"] == 0);
+    }
 }