[libcxx-commits] [libcxx] [libc++][map] Applied `[[nodiscard]]` (PR #169971)
Hans Wennborg via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Dec 15 07:17:13 PST 2025
zmodem wrote:
For `operator[]`, does discarding the return value really suggest a correctness issue?
We're hitting this in lots of code that's using it to insert a default value into a map (or unordered_map) or similar.
Some examples:
- https://source.chromium.org/chromium/_/swiftshader/SwiftShader/+/ff4435d3f92dabbf65e210033ea178359ba7db0e:third_party/SPIRV-Tools/source/opt/ir_context.cpp;l=774
- https://github.com/google/flatbuffers/blob/a86afae9399bbe631d1ea0783f8816e780e236cc/src/idl_parser.cpp#L3991
- https://github.com/v8/v8/blob/3cf7ba6f3659b1f59eac1253e053a7545200280a/src/compiler/turboshaft/late-load-elimination-reducer.cc#L400
- https://source.chromium.org/chromium/chromium/src/+/main:content/browser/renderer_host/back_forward_cache_can_store_document_result.cc;l=251;drc=6699d721a3a4738c9c21ee86f9c77bde0ebe88f1
So far these all look like correct uses, one might even call it an idiom.
Can we reevaluate having `[[nodiscard]]` on `operator[]` in containers where it's also used for insertion?
https://github.com/llvm/llvm-project/pull/169971
More information about the libcxx-commits
mailing list