From bcf4f3ce9a4ab1f31829bfa9446cbeaaeb644e42 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 14 May 2020 19:06:48 +0200 Subject: [PATCH] :memo: add warning for items() on temporary objects #2040 --- include/nlohmann/json.hpp | 5 +++++ single_include/nlohmann/json.hpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 6801326a..b72ea58d 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -4946,6 +4946,11 @@ class basic_json element as string (see example). For primitive types (e.g., numbers), `key()` returns an empty string. + @warning Using `items()` on temporary objects is dangerous. Make sure the + object's lifetime exeeds the iteration. See + for more + information. + @return iteration proxy object wrapping @a ref with an interface to use in range-based for loops diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 12945016..c21a4308 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -20437,6 +20437,11 @@ class basic_json element as string (see example). For primitive types (e.g., numbers), `key()` returns an empty string. + @warning Using `items()` on temporary objects is dangerous. Make sure the + object's lifetime exeeds the iteration. See + for more + information. + @return iteration proxy object wrapping @a ref with an interface to use in range-based for loops