[libcxx-commits] [PATCH] D60145: libcxx: Add _LIBCPP_NODISCARD_EXT to 37 more functions

Nico Weber via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Apr 2 12:00:36 PDT 2019


thakis created this revision.
thakis added a reviewer: EricWF.
Herald added subscribers: jdoerfert, christof.
thakis added a comment.

The test is obviously incomplete. I figured I'd send this out and check if you're generally ok with this; if so I'll update the two test files to make the test comprehensive.


This builds on the work done in r342808 and adds _LIBCPP_NODISCARD_EXT to 37 more functions, namely:

adjacent_find, all_of, any_of, none_of, binary_search, clamp, count_if, count, equal, find_end, find_first_not_of, find_first_of, find_if_not, find_if, find, includes, is_heap, is_heap_until, is_partitioned, is_permutation, is_sorted, is_sorted_until, lexicographical_compare, lower_bound, max, max_element, min, min_element, minmax, minmax_element, mismatch, remove, remove_if, search, search_n, unique, upper_bound

The motivation here is that we noticed that find_if is nodiscard with Visual Studio's standard library, and we deemed that useful (https://crbug.com/948122). https://devblogs.microsoft.com/cppblog/c17-progress-in-vs-2017-15-5-and-15-6/ says "Our criteria for emitting the warning are: discarding the return value is a guaranteed leak [...], discarding the return value is near-guaranteed to be incorrect (e.g. remove()/remove_if()/unique()), or the function is essentially a pure observer (e.g. vector::empty() and std::is_sorted())." so I went through algorithm and tried to apply these criteria.

Some of these, like vector::empty() are already nodiscard per C++ standard and didn't need changing.

I didn't (yet?) go over std::string::find* methods which should probably have _LIBCPP_NODISCARD_EXT too (but not as part of this change).


https://reviews.llvm.org/D60145

Files:
  libcxx/docs/UsingLibcxx.rst
  libcxx/include/algorithm
  libcxx/test/libcxx/diagnostics/nodiscard_extensions.fail.cpp
  libcxx/test/libcxx/diagnostics/nodiscard_extensions.pass.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60145.193337.patch
Type: text/x-patch
Size: 30503 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190402/ce50fee2/attachment-0001.bin>


More information about the libcxx-commits mailing list