[libcxx-commits] [libcxx] [libc++] Mark std::unique_ptr::release() as nodiscard (PR #110847)

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Oct 7 00:19:33 PDT 2024


zmodem wrote:

> @zmodem @davidben When you `release()` the pointer, do you use a custom deleter, or also the default deleter? If it's the former we could look into applying `[[nodiscard]]` only when it's the default deleter. That's why I never closed the referenced bug.

For the cases I've looked at, it's the default deleter. Like in @davidben's examples above, we call .release() because the ownership has been handed over to some other object already.

We did find at least one bug though: https://chromium-review.googlesource.com/c/chromium/src/+/4289548/13/chrome/browser/ui/views/bookmarks/saved_tab_groups/saved_tab_group_bar.cc#197

So marking it nodiscard certainly has value, and would probably have made perfect sense if it was there from the beginning. As to whether the signal-to-noise ratio is high enough now, I don't have a strong opinion. If we do decide to apply it, I would ask for a macro to make it easier to roll out.

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


More information about the libcxx-commits mailing list