Set parents after insert call
Closes #3915
{"label": "nlohmann:develop", "ref": "develop", "sha": "e6cafa573aac6ed9227f752a5371c0b3f436307d"}
### Description

Hi,

I have activated the JSON_DIAGNOSTICS=1 globally in my project and ASSERTION are now fired at runtime.
I tested it on with 3.10.5 and then with latest release 3.11.2.

I have done a minimal example to reproduce the assertion (see minimal code example below)

Is there something wrong with my code?

### Reproduction steps

Run the minimal code example below

### Expected vs. actual results

No ASSERTION should be triggered since without the JSON_DIAGNOSTICS enabled, all seem to work without any memory issues

### Minimal code example

```Shell
json j = json::object();
j["root"] = "root_str";

json jj = json::object();
jj["child"] = json::object();

// If do not push anything in object, then no assert will be produced
jj["child"]["prop1"] = "prop1_value";

// Push all properties of child in parent
j.insert(jj.at("child").begin(), jj.at("child").end());

// Here assert is generated when construct new json 
json k(j);
```


### Error messages

```Shell
nlohmann/json.hpp:19864: void nlohmann::json_abi_diag_v3_11_2::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >::assert_invariant(bool) const [ObjectType = std::map, ArrayType = std::vector, StringType = std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, BooleanType = bool, NumberIntegerType = long, NumberUnsignedType = unsigned long, NumberFloatType = double, AllocatorType = std::allocator, JSONSerializer = adl_serializer, BinaryType = std::vector<unsigned char, std::allocator<unsigned char> >]: Assertion `!check_parents || !is_structured() || std::all_of(begin(), end(), [this](const basic_json & j) { return j.m_parent == this; })' failed.
```


### Compiler and operating system

Clang-10 on Ubuntu 20.04 

### Library version

3.11.2

### Validation

- [ ] The bug also occurs if the latest version from the [`develop`](https://github.com/nlohmann/json/tree/develop) branch is used.
- [ ] I can successfully [compile and run the unit tests](https://github.com/nlohmann/json#execute-unit-tests).
JSON_DIAGNOSTICS trigger assertion
diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp
index 763fd95783..8ec9720ee7 100644
--- a/include/nlohmann/json.hpp
+++ b/include/nlohmann/json.hpp
@@ -3401,6 +3401,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
         }
 
         m_data.m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
+        set_parents();
     }
 
     /// @brief updates a JSON object from another object, overwriting existing keys
diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp
index 7979227a05..0164992148 100644
--- a/single_include/nlohmann/json.hpp
+++ b/single_include/nlohmann/json.hpp
@@ -22948,6 +22948,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
         }
 
         m_data.m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
+        set_parents();
     }
 
     /// @brief updates a JSON object from another object, overwriting existing keys

diff --git a/tests/src/unit-diagnostics.cpp b/tests/src/unit-diagnostics.cpp
index 345d6eee29..472d11e283 100644
--- a/tests/src/unit-diagnostics.cpp
+++ b/tests/src/unit-diagnostics.cpp
@@ -242,4 +242,24 @@ TEST_CASE("Regression tests for extended diagnostics")
             json const j_arr_copy = j_arr;
         }
     }
+
+    SECTION("Regression test for issue #3915 - JSON_DIAGNOSTICS trigger assertion")
+    {
+        json j = json::object();
+        j["root"] = "root_str";
+
+        json jj = json::object();
+        jj["child"] = json::object();
+
+        // If do not push anything in object, then no assert will be produced
+        jj["child"]["prop1"] = "prop1_value";
+
+        // Push all properties of child in parent
+        j.insert(jj.at("child").begin(), jj.at("child").end());
+
+        // Here assert is generated when construct new json
+        const json k(j);
+
+        CHECK(k.dump() == "{\"prop1\":\"prop1_value\",\"root\":\"root_str\"}");
+    }
 }

{"test-diagnostics_cpp11": {"run": "PASS", "test": "NONE", "fix": "PASS"}}
{"test-cbor_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-locale-cpp_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-regression1_cpp17": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-abi_compat_diag": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-conversions_cpp14": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-regression1_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-comparison_legacy_cpp20": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-testsuites_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-ubjson_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "cmake_import_build": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-element_access1_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "cmake_fetch_content2_configure": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-convenience_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "cmake_fetch_content2_build": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-abi_config_default": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-conversions_cpp17": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-disabled_exceptions_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-byte_container_with_subtype_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-large_json_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "cmake_import_minver_build": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-class_parser_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-abi_config_noversion": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "cmake_add_subdirectory_configure": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-bson_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-comparison_cpp20": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-comparison_legacy_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-udt_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-class_iterator_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-binary_formats_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-json_pointer_cpp20": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-meta_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-items_cpp17": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-iterators1_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-abi_compat_inline_ns": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-windows_h_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-user_defined_input_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "cmake_fetch_content_configure": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-merge_patch_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-custom-base-class_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-json_pointer_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-regression2_cpp20": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-pointer_access_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-iterators2_cpp20": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-unicode1_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-comparison_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-reference_access_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-element_access2_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-iterators2_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "cmake_fetch_content_build": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-unicode3_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-ordered_map_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-iterators3_cpp14": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-element_access2_cpp17": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "download_test_data": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-json_patch_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-alt-string_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-modifiers_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-noexcept_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-conversions_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "cmake_target_include_directories_configure": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-deserialization_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-udl_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-wstring_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-constructor2_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "cmake_import_minver_configure": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-msgpack_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-items_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-abi_config_custom": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-class_lexer_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-to_chars_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-class_const_iterator_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "cmake_target_include_directories_build": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-inspection_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-iterators3_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-unicode5_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-element_access2_cpp14": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-udt_macro_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-readme_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-unicode2_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-ordered_json_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-regression2_cpp17": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-no-mem-leak-on-adl-serialize_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-capacity_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-hash_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-type_traits_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-allocator_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-constructor1_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-bjdata_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-algorithms_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-unicode4_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-regression2_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-serialization_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "cmake_import_configure": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-concepts_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-assert_macro_cpp11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test-deserialization_cpp20": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "cmake_add_subdirectory_build": {"run": "PASS", "test": "PASS", "fix": "PASS"}}
{"test-diagnostics_cpp11": {"run": "PASS", "test": "NONE", "fix": "PASS"}}
{"passed_count": 98, "failed_count": 0, "skipped_count": 0, "passed_tests": ["test-locale-cpp_cpp11", "test-comparison_legacy_cpp20", "test-testsuites_cpp11", "test-ubjson_cpp11", "cmake_fetch_content2_configure", "test-convenience_cpp11", "cmake_fetch_content2_build", "test-abi_config_default", "test-conversions_cpp17", "test-disabled_exceptions_cpp11", "cmake_import_minver_build", "test-class_parser_cpp11", "test-abi_config_noversion", "cmake_add_subdirectory_configure", "test-bson_cpp11", "test-comparison_cpp20", "test-comparison_legacy_cpp11", "test-udt_cpp11", "test-class_iterator_cpp11", "test-windows_h_cpp11", "test-merge_patch_cpp11", "test-diagnostics_cpp11", "test-pointer_access_cpp11", "test-comparison_cpp11", "test-element_access2_cpp11", "cmake_fetch_content_build", "test-element_access2_cpp17", "download_test_data", "test-alt-string_cpp11", "test-udl_cpp11", "test-wstring_cpp11", "test-constructor2_cpp11", "cmake_import_minver_configure", "test-msgpack_cpp11", "test-items_cpp11", "test-unicode5_cpp11", "test-element_access2_cpp14", "test-udt_macro_cpp11", "test-unicode2_cpp11", "test-ordered_json_cpp11", "test-regression2_cpp17", "test-capacity_cpp11", "test-allocator_cpp11", "test-constructor1_cpp11", "test-bjdata_cpp11", "test-regression2_cpp11", "test-serialization_cpp11", "test-concepts_cpp11", "test-deserialization_cpp20", "cmake_add_subdirectory_build", "test-cbor_cpp11", "test-regression1_cpp17", "test-abi_compat_diag", "test-conversions_cpp14", "test-regression1_cpp11", "cmake_import_build", "test-element_access1_cpp11", "test-byte_container_with_subtype_cpp11", "test-binary_formats_cpp11", "test-json_pointer_cpp20", "test-meta_cpp11", "test-items_cpp17", "test-iterators1_cpp11", "test-abi_compat_inline_ns", "test-user_defined_input_cpp11", "cmake_fetch_content_configure", "test-custom-base-class_cpp11", "test-json_pointer_cpp11", "test-regression2_cpp20", "test-iterators2_cpp20", "test-unicode1_cpp11", "test-reference_access_cpp11", "test-iterators2_cpp11", "test-unicode3_cpp11", "test-ordered_map_cpp11", "test-iterators3_cpp14", "test-json_patch_cpp11", "test-modifiers_cpp11", "test-noexcept_cpp11", "test-conversions_cpp11", "cmake_target_include_directories_configure", "test-deserialization_cpp11", "test-abi_config_custom", "test-class_lexer_cpp11", "test-to_chars_cpp11", "test-class_const_iterator_cpp11", "cmake_target_include_directories_build", "test-inspection_cpp11", "test-iterators3_cpp11", "test-readme_cpp11", "test-no-mem-leak-on-adl-serialize_cpp11", "test-hash_cpp11", "test-type_traits_cpp11", "test-algorithms_cpp11", "test-unicode4_cpp11", "cmake_import_configure", "test-assert_macro_cpp11", "test-large_json_cpp11"], "failed_tests": [], "skipped_tests": []}
{"passed_count": 97, "failed_count": 0, "skipped_count": 0, "passed_tests": ["test-locale-cpp_cpp11", "test-comparison_legacy_cpp20", "test-testsuites_cpp11", "test-ubjson_cpp11", "cmake_fetch_content2_configure", "test-convenience_cpp11", "cmake_fetch_content2_build", "test-abi_config_default", "test-conversions_cpp17", "test-disabled_exceptions_cpp11", "cmake_import_minver_build", "test-class_parser_cpp11", "test-abi_config_noversion", "cmake_add_subdirectory_configure", "test-bson_cpp11", "test-comparison_cpp20", "test-comparison_legacy_cpp11", "test-udt_cpp11", "test-class_iterator_cpp11", "test-windows_h_cpp11", "test-merge_patch_cpp11", "test-pointer_access_cpp11", "test-comparison_cpp11", "test-element_access2_cpp11", "cmake_fetch_content_build", "test-element_access2_cpp17", "download_test_data", "test-alt-string_cpp11", "test-udl_cpp11", "test-wstring_cpp11", "test-constructor2_cpp11", "cmake_import_minver_configure", "test-msgpack_cpp11", "test-items_cpp11", "test-unicode5_cpp11", "test-element_access2_cpp14", "test-udt_macro_cpp11", "test-unicode2_cpp11", "test-ordered_json_cpp11", "test-regression2_cpp17", "test-capacity_cpp11", "test-allocator_cpp11", "test-constructor1_cpp11", "test-bjdata_cpp11", "test-regression2_cpp11", "test-serialization_cpp11", "test-concepts_cpp11", "test-deserialization_cpp20", "cmake_add_subdirectory_build", "test-cbor_cpp11", "test-regression1_cpp17", "test-abi_compat_diag", "test-conversions_cpp14", "test-regression1_cpp11", "cmake_import_build", "test-element_access1_cpp11", "test-byte_container_with_subtype_cpp11", "test-binary_formats_cpp11", "test-json_pointer_cpp20", "test-meta_cpp11", "test-items_cpp17", "test-iterators1_cpp11", "test-abi_compat_inline_ns", "test-user_defined_input_cpp11", "cmake_fetch_content_configure", "test-custom-base-class_cpp11", "test-json_pointer_cpp11", "test-regression2_cpp20", "test-iterators2_cpp20", "test-unicode1_cpp11", "test-reference_access_cpp11", "test-iterators2_cpp11", "test-unicode3_cpp11", "test-ordered_map_cpp11", "test-iterators3_cpp14", "test-json_patch_cpp11", "test-modifiers_cpp11", "test-noexcept_cpp11", "test-conversions_cpp11", "cmake_target_include_directories_configure", "test-deserialization_cpp11", "test-abi_config_custom", "test-class_lexer_cpp11", "test-to_chars_cpp11", "test-class_const_iterator_cpp11", "cmake_target_include_directories_build", "test-inspection_cpp11", "test-iterators3_cpp11", "test-readme_cpp11", "test-no-mem-leak-on-adl-serialize_cpp11", "test-hash_cpp11", "test-type_traits_cpp11", "test-algorithms_cpp11", "test-unicode4_cpp11", "cmake_import_configure", "test-assert_macro_cpp11", "test-large_json_cpp11"], "failed_tests": [], "skipped_tests": []}
{"passed_count": 98, "failed_count": 0, "skipped_count": 0, "passed_tests": ["test-locale-cpp_cpp11", "test-comparison_legacy_cpp20", "test-testsuites_cpp11", "test-ubjson_cpp11", "cmake_fetch_content2_configure", "test-convenience_cpp11", "cmake_fetch_content2_build", "test-abi_config_default", "test-conversions_cpp17", "test-disabled_exceptions_cpp11", "cmake_import_minver_build", "test-class_parser_cpp11", "test-abi_config_noversion", "cmake_add_subdirectory_configure", "test-bson_cpp11", "test-comparison_cpp20", "test-comparison_legacy_cpp11", "test-udt_cpp11", "test-class_iterator_cpp11", "test-windows_h_cpp11", "test-merge_patch_cpp11", "test-diagnostics_cpp11", "test-pointer_access_cpp11", "test-comparison_cpp11", "test-element_access2_cpp11", "cmake_fetch_content_build", "test-element_access2_cpp17", "download_test_data", "test-alt-string_cpp11", "test-udl_cpp11", "test-wstring_cpp11", "test-constructor2_cpp11", "cmake_import_minver_configure", "test-msgpack_cpp11", "test-items_cpp11", "test-unicode5_cpp11", "test-element_access2_cpp14", "test-udt_macro_cpp11", "test-unicode2_cpp11", "test-ordered_json_cpp11", "test-regression2_cpp17", "test-capacity_cpp11", "test-allocator_cpp11", "test-constructor1_cpp11", "test-bjdata_cpp11", "test-regression2_cpp11", "test-serialization_cpp11", "test-concepts_cpp11", "test-deserialization_cpp20", "cmake_add_subdirectory_build", "test-cbor_cpp11", "test-regression1_cpp17", "test-abi_compat_diag", "test-conversions_cpp14", "test-regression1_cpp11", "cmake_import_build", "test-element_access1_cpp11", "test-byte_container_with_subtype_cpp11", "test-binary_formats_cpp11", "test-json_pointer_cpp20", "test-meta_cpp11", "test-items_cpp17", "test-iterators1_cpp11", "test-abi_compat_inline_ns", "test-user_defined_input_cpp11", "cmake_fetch_content_configure", "test-custom-base-class_cpp11", "test-json_pointer_cpp11", "test-regression2_cpp20", "test-iterators2_cpp20", "test-unicode1_cpp11", "test-reference_access_cpp11", "test-iterators2_cpp11", "test-unicode3_cpp11", "test-ordered_map_cpp11", "test-iterators3_cpp14", "test-json_patch_cpp11", "test-modifiers_cpp11", "test-noexcept_cpp11", "test-conversions_cpp11", "cmake_target_include_directories_configure", "test-deserialization_cpp11", "test-abi_config_custom", "test-class_lexer_cpp11", "test-to_chars_cpp11", "test-class_const_iterator_cpp11", "cmake_target_include_directories_build", "test-inspection_cpp11", "test-iterators3_cpp11", "test-readme_cpp11", "test-no-mem-leak-on-adl-serialize_cpp11", "test-hash_cpp11", "test-type_traits_cpp11", "test-algorithms_cpp11", "test-unicode4_cpp11", "cmake_import_configure", "test-assert_macro_cpp11", "test-large_json_cpp11"], "failed_tests": [], "skipped_tests": []}