Use unique_ptr instead of auto_ptr when possible

Previously we only used it on GCC 6 to avoid deprecated declaration
warnings. Now we are proactive and use it whenever compiling as C++11
(or MSVC2010+).

It also moves the logic for deciding between unique_ptr and auto_ptr
into a single location in config.h.

This fixes some use cases that were previously broken, including:
* CXX=clang++ -std=c++11 -Werror=deprecated-declarations
* CXX=g++-6 -std=c++03 -Werror=deprecated-declarations
This commit is contained in:
AbigailBuccaneer 2017-04-21 15:47:38 +01:00
parent 1335f70bbb
commit 347e1ae46b
3 changed files with 12 additions and 2 deletions

View File

@ -51,6 +51,16 @@
#define JSON_API
#endif
#if !defined(JSON_HAS_UNIQUE_PTR)
#if __cplusplus >= 201103L
#define JSON_HAS_UNIQUE_PTR (1)
#elif _MSC_VER >= 1600
#define JSON_HAS_UNIQUE_PTR (1)
#else
#define JSON_HAS_UNIQUE_PTR (0)
#endif
#endif
// If JSON_NO_INT64 is defined, then Json only support C++ "int" type for
// integer
// Storages, and 64 bits integer support is disabled.

View File

@ -43,7 +43,7 @@ static int stackDepth_g = 0; // see readValue()
namespace Json {
#if __GNUC__ >= 6
#if JSON_HAS_UNIQUE_PTR
typedef std::unique_ptr<CharReader> const CharReaderPtr;
#else
typedef std::auto_ptr<CharReader> CharReaderPtr;

View File

@ -54,7 +54,7 @@
namespace Json {
#if __GNUC__ >= 6
#if JSON_HAS_UNIQUE_PTR
typedef std::unique_ptr<StreamWriter> const StreamWriterPtr;
#else
typedef std::auto_ptr<StreamWriter> StreamWriterPtr;