[libcxx-commits] [libcxx] 17e6bd8 - [libc++][ranges] Fix incorrect integer type in `view_interface` tests.

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jan 11 17:43:18 PST 2023


Author: Konstantin Varlamov
Date: 2023-01-11T17:43:10-08:00
New Revision: 17e6bd8070bb52b4178cf20f92bd429b11851870

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

LOG: [libc++][ranges] Fix incorrect integer type in `view_interface` tests.

`ForwardIter() - ForwardIter()` returns `ptrdiff_t`, and converting it
to an unsigned type isn't guaranteed to produce the same type as
`size_t`.

Reviewed By: #libc, ldionne

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

Added: 
    

Modified: 
    libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp b/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp
index 830f3f77c29ec..b1ed28f80e914 100644
--- a/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp
+++ b/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp
@@ -15,6 +15,7 @@
 #include <ranges>
 
 #include <cassert>
+#include <utility>
 #include "test_macros.h"
 #include "test_iterators.h"
 
@@ -233,17 +234,20 @@ constexpr bool testSize() {
   static_assert(!SizeInvocable<NotSizedSentinel>);
   static_assert( SizeInvocable<ForwardRange>);
 
-  using SignedSize = std::common_type_t<std::ptr
diff _t, std::make_signed_t<std::size_t>>;
+  // Test the test.
+  static_assert(std::same_as<decltype(std::declval<ForwardIter>() - std::declval<ForwardIter>()), std::ptr
diff _t>);
+  using UnsignedSize = std::make_unsigned_t<std::ptr
diff _t>;
+  using SignedSize = std::common_type_t<std::ptr
diff _t, std::make_signed_t<UnsignedSize>>;
   ForwardRange forwardRange;
   assert(forwardRange.size() == 8);
   assert(static_cast<ForwardRange const&>(forwardRange).size() == 8);
 
   assert(std::ranges::size(forwardRange) == 8);
-  static_assert(std::same_as<decltype(std::ranges::size(std::declval<ForwardRange>())), std::size_t>);
+  static_assert(std::same_as<decltype(std::ranges::size(std::declval<ForwardRange>())), UnsignedSize>);
   static_assert(std::same_as<decltype(std::ranges::ssize(std::declval<ForwardRange>())), SignedSize>);
 
   assert(std::ranges::size(static_cast<ForwardRange const&>(forwardRange)) == 8);
-  static_assert(std::same_as<decltype(std::ranges::size(std::declval<ForwardRange const>())), std::size_t>);
+  static_assert(std::same_as<decltype(std::ranges::size(std::declval<ForwardRange const>())), UnsignedSize>);
   static_assert(std::same_as<decltype(std::ranges::ssize(std::declval<ForwardRange const>())), SignedSize>);
 
   SizeIsTen sizeTen;


        


More information about the libcxx-commits mailing list