[libcxx-commits] [libcxx] [libc++] Remove [[nodiscard]] from map etc. operator[] (PR #172444)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 16 01:42:32 PST 2025


https://github.com/philnik777 approved this pull request.

I'm definitely in favour of removing them from map/unordered_map. I think I agree with @frederick-vs-ja's assessment to keep the annotations on `flat_map`, since it is new. However, I do think that a message that `try_emplace` can be used instead would be good there.

We could consider adding `[[nodiscard]]` to map/unordered_map with a message later as well, but we'd definitely have to guard that behind C++17 and possibly make it opt-in, or at the very least easy to opt-out. Anyways, this isn't something we should do now but consider at some point in the future if at all.

TL;DR IMO we can keep the `[[nodiscard]]` in flat_map if we add a message, but I'm happy for that to not be this patch. LGTM.


https://github.com/llvm/llvm-project/pull/172444


More information about the libcxx-commits mailing list