From c333679a9653119ddf19613d3fdc2cb1d42e2a26 Mon Sep 17 00:00:00 2001
From: Niels Lohmann <mail@nlohmann.me>
Date: Sat, 25 Mar 2017 17:25:39 +0100
Subject: [PATCH] :hammer: small refactoring

The solution with a std::runtime_error member is more elegant. It
allows to have std::exception as base class again. However, I still
have no idea why GCC thinks the copy constructor may throw...
---
 src/json.hpp      | 9 ++++++---
 src/json.hpp.re2c | 9 ++++++---
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/json.hpp b/src/json.hpp
index bdada276..5ee3edad 100644
--- a/src/json.hpp
+++ b/src/json.hpp
@@ -123,13 +123,13 @@ Extension of std::exception objects with a member @a id for exception ids.
 
 @since version 3.0.0
 */
-class exception : public std::runtime_error
+class exception : public std::exception
 {
   public:
     /// returns the explanatory string
     virtual const char* what() const noexcept override
     {
-        return std::runtime_error::what();
+        return m.what();
     }
 
     /// the id of the exception
@@ -137,13 +137,16 @@ class exception : public std::runtime_error
 
   protected:
     exception(int id_, const char* what_arg)
-        : std::runtime_error(what_arg), id(id_)
+        : id(id_), m(what_arg)
     {}
 
     static std::string name(const std::string& ename, int id_)
     {
         return "[json.exception." + ename + "." + std::to_string(id_) + "] ";
     }
+
+  private:
+    std::runtime_error m;
 };
 
 /*!
diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c
index d5b12d2c..a51f77e7 100644
--- a/src/json.hpp.re2c
+++ b/src/json.hpp.re2c
@@ -123,13 +123,13 @@ Extension of std::exception objects with a member @a id for exception ids.
 
 @since version 3.0.0
 */
-class exception : public std::runtime_error
+class exception : public std::exception
 {
   public:
     /// returns the explanatory string
     virtual const char* what() const noexcept override
     {
-        return std::runtime_error::what();
+        return m.what();
     }
 
     /// the id of the exception
@@ -137,13 +137,16 @@ class exception : public std::runtime_error
 
   protected:
     exception(int id_, const char* what_arg)
-        : std::runtime_error(what_arg), id(id_)
+        : id(id_), m(what_arg)
     {}
 
     static std::string name(const std::string& ename, int id_)
     {
         return "[json.exception." + ename + "." + std::to_string(id_) + "] ";
     }
+
+  private:
+    std::runtime_error m;
 };
 
 /*!