forward mapped value in object::insert_or_assign assign branch - #1186
forward mapped value in object::insert_or_assign assign branch#1186Ramya-9353 wants to merge 1 commit into
Conversation
|
An automated preview of the documentation is available at https://1186.json.prtest2.cppalliance.org/libs/json/doc/html/index.html If more commits are pushed to the pull request, the docs will rebuild at the same URL. 2026-08-15 12:04:03 UTC |
|
GCOVR code coverage report https://1186.json.prtest2.cppalliance.org/gcovr/index.html Build time: 2026-08-15 12:18:33 UTC |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1186 +/- ##
========================================
Coverage 93.71% 93.71%
========================================
Files 85 85
Lines 8971 8971
========================================
Hits 8407 8407
Misses 564 564
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
|
|
|
Ouch. Thanks for catching this. |
| value v = { 4, 5, 6 }; | ||
| o.insert_or_assign("k2", std::move(v)); | ||
| BOOST_TEST(o.at("k2") == (array{4, 5, 6})); | ||
| BOOST_TEST(v.as_array().empty()); |
There was a problem hiding this comment.
I think, a better check for whether v was actually moved is storing v.as_array().data() and comparing it to o["k2"].as_array().data().

Repro:
insert_or_assign(key, std::move(v))on an existing key, withvon the object's own resource, deep-copiesvand leaves it intact instead of moving it. For a 100-element array the assign branch runs 101 allocations and the source array is still populated afterwards.Cause: the assign branch casts the mapped value to
Mrather thanM&&, so for an rvalue argument it selectsvalue(value const&), which allocates a copy on the source's storage before the copy intosp_. The insert branch one line above already forwards withM&&.Fix: cast to
M&&to match the insert branch. The stored value is unchanged; the redundant copy and the ignored move go away.