[libcxx-commits] [libcxx] e33ca9a - [libc++] Reword std::advance assertion message for consistency with ranges::advance (#138749)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed May 7 09:59:41 PDT 2025


Author: Louis Dionne
Date: 2025-05-07T12:59:38-04:00
New Revision: e33ca9adc8ccb0bc4fa590975898b788ef880dd7

URL: https://github.com/llvm/llvm-project/commit/e33ca9adc8ccb0bc4fa590975898b788ef880dd7
DIFF: https://github.com/llvm/llvm-project/commit/e33ca9adc8ccb0bc4fa590975898b788ef880dd7.diff

LOG: [libc++] Reword std::advance assertion message for consistency with ranges::advance (#138749)

As brought up in https://github.com/llvm/llvm-project/pull/133276.

Added: 
    

Modified: 
    libcxx/include/__iterator/advance.h
    libcxx/test/libcxx/iterators/assert.advance.pass.cpp
    libcxx/test/libcxx/iterators/assert.next.pass.cpp
    libcxx/test/libcxx/iterators/assert.prev.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__iterator/advance.h b/libcxx/include/__iterator/advance.h
index f1a8d28f39aa0..c7d3c1f0e8f05 100644
--- a/libcxx/include/__iterator/advance.h
+++ b/libcxx/include/__iterator/advance.h
@@ -66,7 +66,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 void advance(_InputIter& __i
   typedef typename iterator_traits<_InputIter>::
diff erence_type _Difference;
   _Difference __n = static_cast<_Difference>(std::__convert_to_integral(__orig_n));
   _LIBCPP_ASSERT_PEDANTIC(__has_bidirectional_iterator_category<_InputIter>::value || __n >= 0,
-                          "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
+                          "std::advance: Can only pass a negative `n` with a bidirectional_iterator.");
   std::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
 }
 

diff  --git a/libcxx/test/libcxx/iterators/assert.advance.pass.cpp b/libcxx/test/libcxx/iterators/assert.advance.pass.cpp
index e9d2f27008260..a7e8878b933b2 100644
--- a/libcxx/test/libcxx/iterators/assert.advance.pass.cpp
+++ b/libcxx/test/libcxx/iterators/assert.advance.pass.cpp
@@ -31,7 +31,7 @@ int main(int, char**) {
     forward_iterator<int *> it(a+1);
     std::advance(it, 1);  // should work fine
     std::advance(it, 0);  // should work fine
-    TEST_LIBCPP_ASSERT_FAILURE(std::advance(it, -1), "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
+    TEST_LIBCPP_ASSERT_FAILURE(std::advance(it, -1), "std::advance: Can only pass a negative `n` with a bidirectional_iterator.");
 
     return 0;
 }

diff  --git a/libcxx/test/libcxx/iterators/assert.next.pass.cpp b/libcxx/test/libcxx/iterators/assert.next.pass.cpp
index 1e86723085542..2e0296b72d124 100644
--- a/libcxx/test/libcxx/iterators/assert.next.pass.cpp
+++ b/libcxx/test/libcxx/iterators/assert.next.pass.cpp
@@ -25,7 +25,7 @@ int main(int, char**) {
     forward_iterator<int *> it(a+1);
     (void)std::next(it, 1); // should work fine
     (void)std::next(it, 0); // should work fine
-    TEST_LIBCPP_ASSERT_FAILURE(std::next(it, -1), "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
+    TEST_LIBCPP_ASSERT_FAILURE(std::next(it, -1), "std::advance: Can only pass a negative `n` with a bidirectional_iterator.");
 
     return 0;
 }

diff  --git a/libcxx/test/libcxx/iterators/assert.prev.pass.cpp b/libcxx/test/libcxx/iterators/assert.prev.pass.cpp
index 29b8d6ed5d1e2..deac1edf59e06 100644
--- a/libcxx/test/libcxx/iterators/assert.prev.pass.cpp
+++ b/libcxx/test/libcxx/iterators/assert.prev.pass.cpp
@@ -31,7 +31,7 @@ int main(int, char**) {
     forward_iterator<int *> it(a+1);
     (void)std::prev(it, -1); // should work fine
     (void)std::prev(it, 0);  // should work fine
-    TEST_LIBCPP_ASSERT_FAILURE(std::prev(it, 1), "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
+    TEST_LIBCPP_ASSERT_FAILURE(std::prev(it, 1), "std::advance: Can only pass a negative `n` with a bidirectional_iterator.");
 
     return 0;
 }


        


More information about the libcxx-commits mailing list