[libcxx-commits] [libcxx] 151a7da - [libc++] Fix ssize test that made an assumption about ptrdiff_t being 'long'

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 25 10:12:54 PST 2021


Author: Louis Dionne
Date: 2021-11-25T13:12:47-05:00
New Revision: 151a7dafd31683c8db933a6a03e305184e1218f9

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

LOG: [libc++] Fix ssize test that made an assumption about ptrdiff_t being 'long'

On some platforms like armv7m, the size() method of containers returns
unsigned long, while ptrdiff_t is just int. Hence, std::ssize_t ends up
being long, which is not the same as ptrdiff_t. This is usually not an
issue because std::ptrdiff_t is long, so everything works out, but it
breaks on some more exotic architectures.

Differential Revision: https://reviews.llvm.org/D114563

Added: 
    

Modified: 
    libcxx/test/std/iterators/iterator.container/ssize.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/iterators/iterator.container/ssize.pass.cpp b/libcxx/test/std/iterators/iterator.container/ssize.pass.cpp
index f077e977a35f2..f95cdc1463af4 100644
--- a/libcxx/test/std/iterators/iterator.container/ssize.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.container/ssize.pass.cpp
@@ -78,14 +78,15 @@ int main(int, char**)
     std::list<int>   l; l.push_back(2);
     std::array<int, 1> a; a[0] = 3;
     std::initializer_list<int> il = { 4 };
+    using SSize = std::common_type_t<std::ptr
diff _t, std::make_signed_t<std::size_t>>;
     test_container ( v );
-    ASSERT_SAME_TYPE(ptr
diff _t, decltype(std::ssize(v)));
+    ASSERT_SAME_TYPE(SSize, decltype(std::ssize(v)));
     test_container ( l );
-    ASSERT_SAME_TYPE(ptr
diff _t, decltype(std::ssize(l)));
+    ASSERT_SAME_TYPE(SSize, decltype(std::ssize(l)));
     test_container ( a );
-    ASSERT_SAME_TYPE(ptr
diff _t, decltype(std::ssize(a)));
+    ASSERT_SAME_TYPE(SSize, decltype(std::ssize(a)));
     test_container ( il );
-    ASSERT_SAME_TYPE(ptr
diff _t, decltype(std::ssize(il)));
+    ASSERT_SAME_TYPE(SSize, decltype(std::ssize(il)));
 
     test_const_container ( v );
     test_const_container ( l );
@@ -94,7 +95,7 @@ int main(int, char**)
 
     std::string_view sv{"ABC"};
     test_container ( sv );
-    ASSERT_SAME_TYPE(ptr
diff _t, decltype(std::ssize(sv)));
+    ASSERT_SAME_TYPE(SSize, decltype(std::ssize(sv)));
     test_const_container ( sv );
 
     static constexpr int arrA [] { 1, 2, 3 };


        


More information about the libcxx-commits mailing list