-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[libcxx] applies #134819 to insert_or_assign
with const key_type&
#140124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…pe&` This was missed due to using prvalues in the test case, which were picked up by the rvalue-reference overload instead.
@llvm/pr-subscribers-libcxx Author: Christopher Di Bella (cjdb) ChangesThis was missed due to using prvalues in the test case, which were picked up by the rvalue-reference overload instead. Full diff: https://github.com/llvm/llvm-project/pull/140124.diff 2 Files Affected:
diff --git a/libcxx/include/map b/libcxx/include/map
index 1f650d4f4c3d5..039ed86dc756f 100644
--- a/libcxx/include/map
+++ b/libcxx/include/map
@@ -1205,7 +1205,7 @@ public:
auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args(__h.__i_, __k, __k, std::forward<_Vp>(__v));
if (!__inserted)
- __r->__get_value().second = std::forward<_Vp>(__v);
+ __r->second = std::forward<_Vp>(__v);
return __r;
}
diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/insert_or_assign.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/insert_or_assign.pass.cpp
index 8a129b0295180..0697541b86c24 100644
--- a/libcxx/test/std/containers/associative/map/map.modifiers/insert_or_assign.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.modifiers/insert_or_assign.pass.cpp
@@ -140,14 +140,16 @@ int main(int, char**) {
M::const_iterator it = m.find(2);
Moveable mv1(3, 3.0);
- r = m.insert_or_assign(it, 2, std::move(mv1));
+ const int key1 = 2;
+ r = m.insert_or_assign(it, key1, std::move(mv1));
assert(m.size() == 10);
assert(mv1.moved()); // was moved from
assert(r->first == 2); // key
assert(r->second.get() == 3); // value
Moveable mv2(5, 5.0);
- r = m.insert_or_assign(it, 3, std::move(mv2));
+ const int key2 = 3;
+ r = m.insert_or_assign(it, key2, std::move(mv2));
assert(m.size() == 11);
assert(mv2.moved()); // was moved from
assert(r->first == 3); // key
@@ -155,14 +157,16 @@ int main(int, char**) {
// wrong hint: begin()
Moveable mv3(7, 7.0);
- r = m.insert_or_assign(m.begin(), 4, std::move(mv3));
+ const int key3 = 4;
+ r = m.insert_or_assign(m.begin(), key3, std::move(mv3));
assert(m.size() == 11);
assert(mv3.moved()); // was moved from
assert(r->first == 4); // key
assert(r->second.get() == 7); // value
Moveable mv4(9, 9.0);
- r = m.insert_or_assign(m.begin(), 5, std::move(mv4));
+ const int key4 = 5;
+ r = m.insert_or_assign(m.begin(), key4, std::move(mv4));
assert(m.size() == 12);
assert(mv4.moved()); // was moved from
assert(r->first == 5); // key
@@ -170,14 +174,16 @@ int main(int, char**) {
// wrong hint: end()
Moveable mv5(11, 11.0);
- r = m.insert_or_assign(m.end(), 6, std::move(mv5));
+ const int key5 = 6;
+ r = m.insert_or_assign(m.end(), key5, std::move(mv5));
assert(m.size() == 12);
assert(mv5.moved()); // was moved from
assert(r->first == 6); // key
assert(r->second.get() == 11); // value
Moveable mv6(13, 13.0);
- r = m.insert_or_assign(m.end(), 7, std::move(mv6));
+ const int key6 = 7;
+ r = m.insert_or_assign(m.end(), key6, std::move(mv6));
assert(m.size() == 13);
assert(mv6.moved()); // was moved from
assert(r->first == 7); // key
@@ -185,14 +191,16 @@ int main(int, char**) {
// wrong hint: third element
Moveable mv7(15, 15.0);
- r = m.insert_or_assign(std::next(m.begin(), 2), 8, std::move(mv7));
+ const int key7 = 8;
+ r = m.insert_or_assign(std::next(m.begin(), 2), key7, std::move(mv7));
assert(m.size() == 13);
assert(mv7.moved()); // was moved from
assert(r->first == 8); // key
assert(r->second.get() == 15); // value
Moveable mv8(17, 17.0);
- r = m.insert_or_assign(std::next(m.begin(), 2), 9, std::move(mv8));
+ const int key8 = 9;
+ r = m.insert_or_assign(std::next(m.begin(), 2), key8, std::move(mv8));
assert(m.size() == 14);
assert(mv8.moved()); // was moved from
assert(r->first == 9); // key
|
philnik777
approved these changes
May 15, 2025
✅ With the latest revision this PR passed the C/C++ code formatter. |
frederick-vs-ja
approved these changes
May 16, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This was missed due to using prvalues in the test case, which were picked up by the rvalue-reference overload instead.