From 40aff4182f6e2b11bc8b0525aa965b7b261b3124 Mon Sep 17 00:00:00 2001 From: Lukas Barth Date: Thu, 30 Mar 2017 16:10:03 +0200 Subject: [PATCH 1/3] Pop for every push --- src/json.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/json.hpp b/src/json.hpp index 3345cf2d..90a48538 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -13886,6 +13886,9 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) #pragma GCC diagnostic pop #endif +#if defined(__clang__) + #pragma GCC diagnostic pop +#endif // clean up #undef JSON_CATCH From 0b1b6307a52bc5347589f1c41c79f368ca7c1057 Mon Sep 17 00:00:00 2001 From: Lukas Barth Date: Thu, 30 Mar 2017 16:14:02 +0200 Subject: [PATCH 2/3] Also change the re2c file --- src/json.hpp.re2c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 60bb63c6..d88830b9 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -12919,6 +12919,9 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) #pragma GCC diagnostic pop #endif +#if defined(__clang__) + #pragma GCC diagnostic pop +#endif // clean up #undef JSON_CATCH From d07596a0ea5e66e2677568d4c45b8d9147c9173b Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 30 Mar 2017 17:39:02 +0200 Subject: [PATCH 3/3] :memo: mentioned #540 and fixed #538 --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 803234d8..f8174fa8 100644 --- a/README.md +++ b/README.md @@ -517,9 +517,9 @@ namespace ns { } void from_json(const json& j, person& p) { - p.name = j["name"].get(); - p.address = j["address"].get(); - p.age = j["age"].get(); + p.name = j.at("name").get(); + p.address = j.at("address").get(); + p.age = j.at("age").get(); } } // namespace ns ``` @@ -531,6 +531,7 @@ Some important things: * Those methods **MUST** be in your type's namespace (which can be the global namespace), or the library will not be able to locate them (in this example, they are in namespace `ns`, where `person` is defined). * When using `get()`, `your_type` **MUST** be [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible). (There is a way to bypass this requirement described later.) +* In function `from_json`, use function [`at()`](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a93403e803947b86f4da2d1fb3345cf2c.html#a93403e803947b86f4da2d1fb3345cf2c) to access the object values rather than `operator[]`. In case a key does not exists, `at` throws an exception that you can handle, whereas `operator[]` exhibits undefined behavior. #### How do I convert third-party types? @@ -833,6 +834,7 @@ I deeply appreciate the help of the following people. - [TedLyngmo](https://github.com/TedLyngmo) noted a typo in the README, removed unnecessary bit arithmetic, and fixed some `-Weffc++` warnings. - [Krzysztof Woś](https://github.com/krzysztofwos) made exceptions more visible. - [ftillier](https://github.com/ftillier) fixed a compiler warning. +- [tinloaf](https://github.com/tinloaf) made sure all pushed warnings are properly popped. Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone.