From 7b8fd864e220eeb2b7eac06f20a921ea0d93983f Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 1 Mar 2017 17:49:03 +0100 Subject: [PATCH] :fire: removed deprecated constructor #480 The constructor basic_json(std::istream&, const parser_callback_t) has been deprecated since version 2.0.0. This commit removes it together with its code example, deprecation macro, and test cases. The code now also compiles with -W-deprecated-declarations. --- Makefile | 2 - doc/examples/basic_json__istream.cpp | 57 ------------------------- doc/examples/basic_json__istream.link | 1 - doc/examples/basic_json__istream.output | 34 --------------- src/json.hpp | 44 ------------------- src/json.hpp.re2c | 44 ------------------- test/src/unit-constructor1.cpp | 36 ---------------- 7 files changed, 218 deletions(-) delete mode 100644 doc/examples/basic_json__istream.cpp delete mode 100644 doc/examples/basic_json__istream.link delete mode 100644 doc/examples/basic_json__istream.output diff --git a/Makefile b/Makefile index ac75bcaf7..1b7cf8c17 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,6 @@ doctest: # -Wno-documentation-unknown-command: code uses user-defined commands like @complexity # -Wno-exit-time-destructors: warning in Catch code # -Wno-keyword-macro: unit-tests use "#define private public" -# -Wno-deprecated-declarations: some functions are deprecated until 3.0.0 # -Wno-range-loop-analysis: iterator_wrapper tests tests "for(const auto i...)" pedantic: $(MAKE) json_unit CXXFLAGS="\ @@ -59,7 +58,6 @@ pedantic: -Wno-documentation-unknown-command \ -Wno-exit-time-destructors \ -Wno-keyword-macro \ - -Wno-deprecated-declarations \ -Wno-range-loop-analysis" diff --git a/doc/examples/basic_json__istream.cpp b/doc/examples/basic_json__istream.cpp deleted file mode 100644 index 32885b22c..000000000 --- a/doc/examples/basic_json__istream.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include - -using json = nlohmann::json; - -int main() -{ - // a JSON text - auto text = R"( - { - "Image": { - "Width": 800, - "Height": 600, - "Title": "View from 15th Floor", - "Thumbnail": { - "Url": "http://www.example.com/image/481989943", - "Height": 125, - "Width": 100 - }, - "Animated" : false, - "IDs": [116, 943, 234, 38793] - } - } - )"; - - // fill a stream with JSON text - std::stringstream ss; - ss << text; - - // create JSON from stream - json j_complete(ss); // deprecated! - // shall be replaced by: json j_complete = json::parse(ss); - std::cout << std::setw(4) << j_complete << "\n\n"; - - - // define parser callback - json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed) - { - // skip object elements with key "Thumbnail" - if (event == json::parse_event_t::key and parsed == json("Thumbnail")) - { - return false; - } - else - { - return true; - } - }; - - // fill a stream with JSON text - ss.clear(); - ss << text; - - // create JSON from stream (with callback) - json j_filtered(ss, cb); - // shall be replaced by: json j_filtered = json::parse(ss, cb); - std::cout << std::setw(4) << j_filtered << '\n'; -} \ No newline at end of file diff --git a/doc/examples/basic_json__istream.link b/doc/examples/basic_json__istream.link deleted file mode 100644 index eb165e2fd..000000000 --- a/doc/examples/basic_json__istream.link +++ /dev/null @@ -1 +0,0 @@ -online \ No newline at end of file diff --git a/doc/examples/basic_json__istream.output b/doc/examples/basic_json__istream.output deleted file mode 100644 index 279a7ff74..000000000 --- a/doc/examples/basic_json__istream.output +++ /dev/null @@ -1,34 +0,0 @@ -{ - "Image": { - "Animated": false, - "Height": 600, - "IDs": [ - 116, - 943, - 234, - 38793 - ], - "Thumbnail": { - "Height": 125, - "Url": "http://www.example.com/image/481989943", - "Width": 100 - }, - "Title": "View from 15th Floor", - "Width": 800 - } -} - -{ - "Image": { - "Animated": false, - "Height": 600, - "IDs": [ - 116, - 943, - 234, - 38793 - ], - "Title": "View from 15th Floor", - "Width": 800 - } -} diff --git a/src/json.hpp b/src/json.hpp index 507ec9f2f..ff0ce5add 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -81,15 +81,6 @@ SOFTWARE. #pragma GCC diagnostic ignored "-Wdocumentation" #endif -// allow for portable deprecation warnings -#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) - #define JSON_DEPRECATED __attribute__((deprecated)) -#elif defined(_MSC_VER) - #define JSON_DEPRECATED __declspec(deprecated) -#else - #define JSON_DEPRECATED -#endif - // allow to disable exceptions #if not defined(JSON_NOEXCEPTION) || defined(__EXCEPTIONS) #define JSON_THROW(exception) throw exception @@ -2362,40 +2353,6 @@ class basic_json assert_invariant(); } - /*! - @brief construct a JSON value given an input stream - - @param[in,out] i stream to read a serialized JSON value from - @param[in] cb a parser callback function of type @ref parser_callback_t - which is used to control the deserialization by filtering unwanted values - (optional) - - @complexity Linear in the length of the input. The parser is a predictive - LL(1) parser. The complexity can be higher if the parser callback function - @a cb has a super-linear complexity. - - @note A UTF-8 byte order mark is silently ignored. - - @deprecated This constructor is deprecated and will be removed in version - 3.0.0 to unify the interface of the library. Deserialization will be - done by stream operators or by calling one of the `parse` functions, - e.g. @ref parse(std::istream&, const parser_callback_t). That is, calls - like `json j(i);` for an input stream @a i need to be replaced by - `json j = json::parse(i);`. See the example below. - - @liveexample{The example below demonstrates constructing a JSON value from - a `std::stringstream` with and without callback - function.,basic_json__istream} - - @since version 2.0.0, deprecated in version 2.0.3, to be removed in - version 3.0.0 - */ - JSON_DEPRECATED - explicit basic_json(std::istream& i, const parser_callback_t cb = nullptr) - { - *this = parser(i, cb).parse(); - assert_invariant(); - } /////////////////////////////////////// // other constructors and destructor // @@ -13113,7 +13070,6 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std // clean up #undef JSON_CATCH -#undef JSON_DEPRECATED #undef JSON_THROW #undef JSON_TRY diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 1dbbb3b53..fc7cf9653 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -81,15 +81,6 @@ SOFTWARE. #pragma GCC diagnostic ignored "-Wdocumentation" #endif -// allow for portable deprecation warnings -#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) - #define JSON_DEPRECATED __attribute__((deprecated)) -#elif defined(_MSC_VER) - #define JSON_DEPRECATED __declspec(deprecated) -#else - #define JSON_DEPRECATED -#endif - // allow to disable exceptions #if not defined(JSON_NOEXCEPTION) || defined(__EXCEPTIONS) #define JSON_THROW(exception) throw exception @@ -2362,40 +2353,6 @@ class basic_json assert_invariant(); } - /*! - @brief construct a JSON value given an input stream - - @param[in,out] i stream to read a serialized JSON value from - @param[in] cb a parser callback function of type @ref parser_callback_t - which is used to control the deserialization by filtering unwanted values - (optional) - - @complexity Linear in the length of the input. The parser is a predictive - LL(1) parser. The complexity can be higher if the parser callback function - @a cb has a super-linear complexity. - - @note A UTF-8 byte order mark is silently ignored. - - @deprecated This constructor is deprecated and will be removed in version - 3.0.0 to unify the interface of the library. Deserialization will be - done by stream operators or by calling one of the `parse` functions, - e.g. @ref parse(std::istream&, const parser_callback_t). That is, calls - like `json j(i);` for an input stream @a i need to be replaced by - `json j = json::parse(i);`. See the example below. - - @liveexample{The example below demonstrates constructing a JSON value from - a `std::stringstream` with and without callback - function.,basic_json__istream} - - @since version 2.0.0, deprecated in version 2.0.3, to be removed in - version 3.0.0 - */ - JSON_DEPRECATED - explicit basic_json(std::istream& i, const parser_callback_t cb = nullptr) - { - *this = parser(i, cb).parse(); - assert_invariant(); - } /////////////////////////////////////// // other constructors and destructor // @@ -12147,7 +12104,6 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std // clean up #undef JSON_CATCH -#undef JSON_DEPRECATED #undef JSON_THROW #undef JSON_TRY diff --git a/test/src/unit-constructor1.cpp b/test/src/unit-constructor1.cpp index b3354b58f..9363f0ba2 100644 --- a/test/src/unit-constructor1.cpp +++ b/test/src/unit-constructor1.cpp @@ -1281,40 +1281,4 @@ TEST_CASE("constructors") } } } - - SECTION("create a JSON value from an input stream") - { - SECTION("std::stringstream") - { - std::stringstream ss; - ss << "[\"foo\",1,2,3,false,{\"one\":1}]"; - json j(ss); - CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}})); - } - - SECTION("with callback function") - { - std::stringstream ss; - ss << "[\"foo\",1,2,3,false,{\"one\":1}]"; - json j(ss, [](int, json::parse_event_t, const json & val) - { - // filter all number(2) elements - if (val == json(2)) - { - return false; - } - else - { - return true; - } - }); - CHECK(j == json({"foo", 1, 3, false, {{"one", 1}}})); - } - - SECTION("std::ifstream") - { - std::ifstream f("test/data/json_tests/pass1.json"); - json j(f); - } - } }