Skip to content

Commit 347e1ae

Browse files
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
1 parent 1335f70 commit 347e1ae

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

Diff for: include/json/config.h

+10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@
5151
#define JSON_API
5252
#endif
5353

54+
#if !defined(JSON_HAS_UNIQUE_PTR)
55+
#if __cplusplus >= 201103L
56+
#define JSON_HAS_UNIQUE_PTR (1)
57+
#elif _MSC_VER >= 1600
58+
#define JSON_HAS_UNIQUE_PTR (1)
59+
#else
60+
#define JSON_HAS_UNIQUE_PTR (0)
61+
#endif
62+
#endif
63+
5464
// If JSON_NO_INT64 is defined, then Json only support C++ "int" type for
5565
// integer
5666
// Storages, and 64 bits integer support is disabled.

Diff for: src/lib_json/json_reader.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static int stackDepth_g = 0; // see readValue()
4343

4444
namespace Json {
4545

46-
#if __GNUC__ >= 6
46+
#if JSON_HAS_UNIQUE_PTR
4747
typedef std::unique_ptr<CharReader> const CharReaderPtr;
4848
#else
4949
typedef std::auto_ptr<CharReader> CharReaderPtr;

Diff for: src/lib_json/json_writer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
namespace Json {
5656

57-
#if __GNUC__ >= 6
57+
#if JSON_HAS_UNIQUE_PTR
5858
typedef std::unique_ptr<StreamWriter> const StreamWriterPtr;
5959
#else
6060
typedef std::auto_ptr<StreamWriter> StreamWriterPtr;

0 commit comments

Comments
 (0)