[libcxx-commits] [libcxx] [libc++] Remove [[nodiscard]] from map etc. operator[] (PR #172444)
Hans Wennborg via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Dec 16 01:40:57 PST 2025
================
@@ -465,13 +465,13 @@ class flat_map {
}
// [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)
----------------
zmodem wrote:
It sounds like we're on the same page about `map` and `unordered_map`.
I don't feel particularly strongly about `flat_map` since we don't have many uses, but I think we should strive for consistency between the interfaces.
https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant says nodiscard should be used
> where discarding the return value is most likely a correctness issue. For example a locking constructor in `unique_lock.`
I don't think nodiscard on these `operator[]`'s meets the criterion of "most likely a correctness issue". Of the instances I've seen so far, none have been a correctness issue. Do you have any data that suggests otherwise?
https://github.com/llvm/llvm-project/pull/172444
More information about the libcxx-commits
mailing list