-
- Downloads
libstdc++: Add nodiscard in <algorithm>
Add the [[nodiscard]] attribute to several functions in <algorithm>. These all have no side effects and are only called for their return value (e.g. std::count) or produce a result that must not be discarded for correctness (e.g. std::remove). I was intending to add the attribute to a number of other functions like std::copy_if, std::unique_copy, std::set_union, and std::set_difference. I stopped when I noticed that MSVC doesn't use it on those functions, which I suspect is because they're often used with an insert iterator (e.g. std::back_insert_iterator). In that case it doesn't matter if you discard the result, because you have the container to tell you how many elements were copied to the output range. libstdc++-v3/ChangeLog: * include/bits/stl_algo.h (find_end, all_of, none_of, any_of) (find_if_not, is_partitioned, partition_point, remove) (remove_if, unique, lower_bound, upper_bound, equal_range) (binary_search, includes, is_sorted, is_sorted_until, minmax) (minmax_element, is_permutation, clamp, find_if, find_first_of) (adjacent_find, count, count_if, search, search_n, min_element) (max_element): Add nodiscard attribute. * include/bits/stl_algobase.h (min, max, lower_bound, equal) (lexicographical_compare, lexicographical_compare_three_way) (mismatch): Likewise. * include/bits/stl_heap.h (is_heap, is_heap_until): Likewise. * testsuite/25_algorithms/equal/debug/1_neg.cc: Add dg-warning. * testsuite/25_algorithms/equal/debug/2_neg.cc: Likewise. * testsuite/25_algorithms/equal/debug/3_neg.cc: Likewise. * testsuite/25_algorithms/find_first_of/concept_check_1.cc: Likewise. * testsuite/25_algorithms/is_permutation/2.cc: Likewise. * testsuite/25_algorithms/lexicographical_compare/71545.cc: Likewise. * testsuite/25_algorithms/lower_bound/33613.cc: Likewise. * testsuite/25_algorithms/lower_bound/debug/irreflexive.cc: Likewise. * testsuite/25_algorithms/lower_bound/debug/partitioned_neg.cc: Likewise. * testsuite/25_algorithms/lower_bound/debug/partitioned_pred_neg.cc: Likewise. * testsuite/25_algorithms/minmax/3.cc: Likewise. * testsuite/25_algorithms/search/78346.cc: Likewise. * testsuite/25_algorithms/search_n/58358.cc: Likewise. * testsuite/25_algorithms/unique/1.cc: Likewise. * testsuite/25_algorithms/unique/11480.cc: Likewise. * testsuite/25_algorithms/upper_bound/33613.cc: Likewise. * testsuite/25_algorithms/upper_bound/debug/partitioned_neg.cc: Likewise. * testsuite/25_algorithms/upper_bound/debug/partitioned_pred_neg.cc: Likewise. * testsuite/ext/concept_checks.cc: Likewise. * testsuite/ext/is_heap/47709.cc: Likewise. * testsuite/ext/is_sorted/cxx0x.cc: Likewise.
Showing
- libstdc++-v3/include/bits/stl_algo.h 51 additions, 51 deletionslibstdc++-v3/include/bits/stl_algo.h
- libstdc++-v3/include/bits/stl_algobase.h 16 additions, 16 deletionslibstdc++-v3/include/bits/stl_algobase.h
- libstdc++-v3/include/bits/stl_heap.h 4 additions, 4 deletionslibstdc++-v3/include/bits/stl_heap.h
- libstdc++-v3/testsuite/25_algorithms/equal/debug/1_neg.cc 1 addition, 0 deletionslibstdc++-v3/testsuite/25_algorithms/equal/debug/1_neg.cc
- libstdc++-v3/testsuite/25_algorithms/equal/debug/2_neg.cc 1 addition, 0 deletionslibstdc++-v3/testsuite/25_algorithms/equal/debug/2_neg.cc
- libstdc++-v3/testsuite/25_algorithms/equal/debug/3_neg.cc 1 addition, 0 deletionslibstdc++-v3/testsuite/25_algorithms/equal/debug/3_neg.cc
- libstdc++-v3/testsuite/25_algorithms/find_first_of/concept_check_1.cc 1 addition, 0 deletions.../testsuite/25_algorithms/find_first_of/concept_check_1.cc
- libstdc++-v3/testsuite/25_algorithms/is_permutation/2.cc 1 addition, 0 deletionslibstdc++-v3/testsuite/25_algorithms/is_permutation/2.cc
- libstdc++-v3/testsuite/25_algorithms/lexicographical_compare/71545.cc 1 addition, 0 deletions.../testsuite/25_algorithms/lexicographical_compare/71545.cc
- libstdc++-v3/testsuite/25_algorithms/lower_bound/33613.cc 1 addition, 0 deletionslibstdc++-v3/testsuite/25_algorithms/lower_bound/33613.cc
- libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/irreflexive.cc 1 addition, 0 deletions.../testsuite/25_algorithms/lower_bound/debug/irreflexive.cc
- libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/partitioned_neg.cc 1 addition, 0 deletions...tsuite/25_algorithms/lower_bound/debug/partitioned_neg.cc
- libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/partitioned_pred_neg.cc 1 addition, 0 deletions...e/25_algorithms/lower_bound/debug/partitioned_pred_neg.cc
- libstdc++-v3/testsuite/25_algorithms/minmax/3.cc 1 addition, 0 deletionslibstdc++-v3/testsuite/25_algorithms/minmax/3.cc
- libstdc++-v3/testsuite/25_algorithms/search/78346.cc 1 addition, 0 deletionslibstdc++-v3/testsuite/25_algorithms/search/78346.cc
- libstdc++-v3/testsuite/25_algorithms/search_n/58358.cc 1 addition, 0 deletionslibstdc++-v3/testsuite/25_algorithms/search_n/58358.cc
- libstdc++-v3/testsuite/25_algorithms/unique/1.cc 1 addition, 0 deletionslibstdc++-v3/testsuite/25_algorithms/unique/1.cc
- libstdc++-v3/testsuite/25_algorithms/unique/11480.cc 1 addition, 1 deletionlibstdc++-v3/testsuite/25_algorithms/unique/11480.cc
- libstdc++-v3/testsuite/25_algorithms/upper_bound/33613.cc 1 addition, 0 deletionslibstdc++-v3/testsuite/25_algorithms/upper_bound/33613.cc
- libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/partitioned_neg.cc 1 addition, 0 deletions...tsuite/25_algorithms/upper_bound/debug/partitioned_neg.cc
Loading
Please register or sign in to comment