forward mapped value in object::insert_or_assign assign branch - #1186
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-19 06:03:58 UTC |
|
GCOVR code coverage report https://1186.json.prtest2.cppalliance.org/gcovr/index.html Build time: 2026-08-19 06:37:59 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 8980 +9
========================================
+ Hits 8407 8416 +9
Misses 564 564
... and 1 file with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
|
|
|
Ouch. Thanks for catching this. |
|
|
|
|



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.