[libcxx-commits] [libcxx] [libc++][hardening] Categorize more assertions. (PR #75918)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Dec 19 02:23:16 PST 2023
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 849c951191f2d272d97bd801e7dd73f44b11792e 30b70b23d9e7819ff2ce4acb214bf71dff4d31e7 -- libcxx/test/libcxx/iterators/predef.iterators/counted.iterator/assert.pass.cpp libcxx/test/libcxx/iterators/predef.iterators/iterators.common/assert.pass.cpp libcxx/include/__algorithm/pop_heap.h libcxx/include/__algorithm/ranges_max.h libcxx/include/__algorithm/ranges_min.h libcxx/include/__algorithm/ranges_minmax.h libcxx/include/__algorithm/sample.h libcxx/include/__algorithm/sift_down.h libcxx/include/__algorithm/sort.h libcxx/include/__charconv/to_chars_base_10.h libcxx/include/__charconv/to_chars_integral.h libcxx/include/__charconv/traits.h libcxx/include/__chrono/parser_std_format_spec.h libcxx/include/__config libcxx/include/__filesystem/path_iterator.h libcxx/include/__format/buffer.h libcxx/include/__format/format_arg.h libcxx/include/__format/formatter_bool.h libcxx/include/__format/formatter_floating_point.h libcxx/include/__format/formatter_integral.h libcxx/include/__format/formatter_output.h libcxx/include/__format/formatter_string.h libcxx/include/__format/parser_std_format_spec.h libcxx/include/__format/range_formatter.h libcxx/include/__format/unicode.h libcxx/include/__format/write_escaped.h libcxx/include/__hash_table libcxx/include/__iterator/advance.h libcxx/include/__iterator/common_iterator.h libcxx/include/__iterator/counted_iterator.h libcxx/include/__iterator/next.h libcxx/include/__iterator/prev.h libcxx/include/__random/negative_binomial_distribution.h libcxx/include/__ranges/chunk_by_view.h libcxx/include/__ranges/drop_while_view.h libcxx/include/__ranges/filter_view.h libcxx/include/__ranges/subrange.h libcxx/include/__ranges/view_interface.h libcxx/include/__thread/thread.h libcxx/include/__utility/exception_guard.h libcxx/include/__utility/is_pointer_in_range.h libcxx/include/__utility/unreachable.h libcxx/include/experimental/__simd/vec_ext.h libcxx/include/print libcxx/include/set libcxx/src/filesystem/error.h libcxx/src/filesystem/format_string.h libcxx/src/filesystem/posix_compat.h libcxx/src/include/to_chars_floating_point.h libcxx/src/memory_resource.cpp libcxx/src/strstream.cpp libcxx/src/support/ibm/xlocale_zos.cpp libcxx/src/system_error.cpp libcxx/test/libcxx/algorithms/alg.sorting/assert.min.max.pass.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libcxx/include/__iterator/advance.h b/libcxx/include/__iterator/advance.h
index de6df65378..50931c281f 100644
--- a/libcxx/include/__iterator/advance.h
+++ b/libcxx/include/__iterator/advance.h
@@ -65,7 +65,7 @@ template < class _InputIter,
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 void advance(_InputIter& __i, _Distance __orig_n) {
typedef typename iterator_traits<_InputIter>::difference_type _Difference;
_Difference __n = static_cast<_Difference>(std::__convert_to_integral(__orig_n));
- // Calling `advance` with a negative value on a non-bidirectional iterator in the current implementation.
+ // Calling `advance` with a negative value on a non-bidirectional iterator in the current implementation.
_LIBCPP_ASSERT_PEDANTIC(__n >= 0 || __has_bidirectional_iterator_category<_InputIter>::value,
"Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
std::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
diff --git a/libcxx/include/__iterator/next.h b/libcxx/include/__iterator/next.h
index 2331c004d3..9d6206ed5d 100644
--- a/libcxx/include/__iterator/next.h
+++ b/libcxx/include/__iterator/next.h
@@ -27,13 +27,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _InputIter
next(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n = 1) {
- // Calling `advance` with a negative value on a non-bidirectional iterator in the current implementation. Note that
- // this check duplicates the similar check in `std::advance`.
- _LIBCPP_ASSERT_PEDANTIC(__n >= 0 || __has_bidirectional_iterator_category<_InputIter>::value,
- "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
+ // Calling `advance` with a negative value on a non-bidirectional iterator in the current implementation. Note that
+ // this check duplicates the similar check in `std::advance`.
+ _LIBCPP_ASSERT_PEDANTIC(__n >= 0 || __has_bidirectional_iterator_category<_InputIter>::value,
+ "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
- std::advance(__x, __n);
- return __x;
+ std::advance(__x, __n);
+ return __x;
}
#if _LIBCPP_STD_VER >= 20
diff --git a/libcxx/include/__iterator/prev.h b/libcxx/include/__iterator/prev.h
index cb0e1fcb9b..a0edcf174b 100644
--- a/libcxx/include/__iterator/prev.h
+++ b/libcxx/include/__iterator/prev.h
@@ -27,10 +27,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _InputIter
prev(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n = 1) {
- // Calling `advance` with a negative value on a non-bidirectional iterator in the current implementation. Note that
- // this check duplicates the similar check in `std::advance`.
- _LIBCPP_ASSERT_PEDANTIC(__n <= 0 || __has_bidirectional_iterator_category<_InputIter>::value,
- "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
+ // Calling `advance` with a negative value on a non-bidirectional iterator in the current implementation. Note that
+ // this check duplicates the similar check in `std::advance`.
+ _LIBCPP_ASSERT_PEDANTIC(__n <= 0 || __has_bidirectional_iterator_category<_InputIter>::value,
+ "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
std::advance(__x, -__n);
return __x;
}
diff --git a/libcxx/include/__ranges/filter_view.h b/libcxx/include/__ranges/filter_view.h
index 92c55538a5..23739a8481 100644
--- a/libcxx/include/__ranges/filter_view.h
+++ b/libcxx/include/__ranges/filter_view.h
@@ -83,9 +83,9 @@ public:
_LIBCPP_HIDE_FROM_ABI constexpr _Pred const& pred() const { return *__pred_; }
_LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() {
- // Note: this duplicates a check in `optional` but provides a better error message.
- _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
- __pred_.__has_value(), "Trying to call begin() on a filter_view that does not have a valid predicate.");
+ // Note: this duplicates a check in `optional` but provides a better error message.
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
+ __pred_.__has_value(), "Trying to call begin() on a filter_view that does not have a valid predicate.");
if constexpr (_UseCache) {
if (!__cached_begin_.__has_value()) {
__cached_begin_.__emplace(ranges::find_if(__base_, std::ref(*__pred_)));
``````````
</details>
https://github.com/llvm/llvm-project/pull/75918
More information about the libcxx-commits
mailing list