diff --git a/libcxx/include/__flat_map/flat_map.h b/libcxx/include/__flat_map/flat_map.h index 84b60cdc9ae2..4cd938b54cbf 100644 --- a/libcxx/include/__flat_map/flat_map.h +++ b/libcxx/include/__flat_map/flat_map.h @@ -465,13 +465,13 @@ public: } // [flat.map.access], element access - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& operator[](const key_type& __x) + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& operator[](const key_type& __x) requires is_constructible_v { return try_emplace(__x).first->second; } - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& operator[](key_type&& __x) + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& operator[](key_type&& __x) requires is_constructible_v { return try_emplace(std::move(__x)).first->second; @@ -480,7 +480,7 @@ public: template requires(__is_compare_transparent && is_constructible_v && is_constructible_v && !is_convertible_v<_Kp &&, const_iterator> && !is_convertible_v<_Kp &&, iterator>) - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& operator[](_Kp&& __x) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& operator[](_Kp&& __x) { return try_emplace(std::forward<_Kp>(__x)).first->second; } diff --git a/libcxx/include/map b/libcxx/include/map index 6414c35a0799..03c92e152e04 100644 --- a/libcxx/include/map +++ b/libcxx/include/map @@ -1092,9 +1092,9 @@ public: [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __tree_.size(); } [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __tree_.max_size(); } - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](const key_type& __k); + _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](const key_type& __k); # ifndef _LIBCPP_CXX03_LANG - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](key_type&& __k); + _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](key_type&& __k); # endif template = 20 - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](const key_type& __k); + _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](const key_type& __k); # ifndef _LIBCPP_CXX03_LANG - [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](key_type&& __k); + _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](key_type&& __k); # endif [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI mapped_type& at(const key_type& __k); diff --git a/libcxx/test/libcxx/diagnostics/flat_map.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/flat_map.nodiscard.verify.cpp index 7d75083157ae..d2000b66147d 100644 --- a/libcxx/test/libcxx/diagnostics/flat_map.nodiscard.verify.cpp +++ b/libcxx/test/libcxx/diagnostics/flat_map.nodiscard.verify.cpp @@ -66,9 +66,9 @@ void test() { TransparentKey tkey; std::flat_map nfm; - nfm[key]; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} - fm[std::move(key)]; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} - fm[std::move(tkey)]; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + nfm[key]; // no-warning + fm[std::move(key)]; // no-warning + fm[std::move(tkey)]; // no-warning fm.at(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} cfm.at(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} diff --git a/libcxx/test/libcxx/diagnostics/map.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/map.nodiscard.verify.cpp index ea110c35c03d..20218b50e6c6 100644 --- a/libcxx/test/libcxx/diagnostics/map.nodiscard.verify.cpp +++ b/libcxx/test/libcxx/diagnostics/map.nodiscard.verify.cpp @@ -55,8 +55,8 @@ void test() { int key = 0; - m[key]; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} - m[std::move(key)]; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + m[key]; // no-warning + m[std::move(key)]; // no-warning #if TEST_STD_VER >= 14 std::map> strMap; diff --git a/libcxx/test/libcxx/diagnostics/unordered_map.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/unordered_map.nodiscard.verify.cpp index 064b7a2fb444..074755690520 100644 --- a/libcxx/test/libcxx/diagnostics/unordered_map.nodiscard.verify.cpp +++ b/libcxx/test/libcxx/diagnostics/unordered_map.nodiscard.verify.cpp @@ -81,8 +81,8 @@ void test() { ctm.equal_range(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} #endif - m[key]; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} - m[std::move(key)]; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + m[key]; // no-warning + m[std::move(key)]; // no-warning m.at(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} cm.at(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}