diff --git a/libcxx/test/std/iterators/iterator.primitives/iterator.traits/cxx20_iterator_traits.compile.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/iterator.traits/cxx20_iterator_traits.compile.pass.cpp --- a/libcxx/test/std/iterators/iterator.primitives/iterator.traits/cxx20_iterator_traits.compile.pass.cpp +++ b/libcxx/test/std/iterators/iterator.primitives/iterator.traits/cxx20_iterator_traits.compile.pass.cpp @@ -66,155 +66,133 @@ } template -constexpr bool testConstWithoutConcept() { +constexpr bool testConst() { using Traits = std::iterator_traits; static_assert(std::same_as); static_assert(std::same_as); static_assert(std::same_as); static_assert(std::same_as); static_assert(std::same_as); - static_assert(!has_iterator_concept_v); - - return true; -} - -template -constexpr bool testConstWithConcept() { - using Traits = std::iterator_traits; - static_assert(std::same_as); - static_assert(std::same_as); - static_assert(std::same_as); - static_assert(std::same_as); - static_assert(std::same_as); - static_assert(std::same_as); + if constexpr (std::is_pointer_v) { + static_assert(std::same_as); + } else { + static_assert(!has_iterator_concept_v); + } return true; } template -constexpr bool testWithoutConcept() { +constexpr bool test() { using Traits = std::iterator_traits; static_assert(std::same_as); static_assert(std::same_as); static_assert(std::same_as); static_assert(std::same_as); static_assert(std::same_as); - static_assert(!has_iterator_concept_v); - - return true; -} - -template -constexpr bool testWithConcept() { - using Traits = std::iterator_traits; - static_assert(std::same_as); - static_assert(std::same_as); - static_assert(std::same_as); - static_assert(std::same_as); - static_assert(std::same_as); - static_assert(std::same_as); + if constexpr (std::is_pointer_v) { + static_assert(std::same_as); + } else { + static_assert(!has_iterator_concept_v); + } return true; } template -constexpr bool testWithoutConcept() { - using Traits = std::iterator_traits; - static_assert(std::same_as); - static_assert(std::same_as); - static_assert(std::same_as); - static_assert(std::same_as); - static_assert(std::same_as); - static_assert(!has_iterator_concept_v); - - return true; -} - -template -constexpr bool testWithConcept() { +constexpr bool test() { using Traits = std::iterator_traits; static_assert(std::same_as); static_assert(std::same_as); static_assert(std::same_as); static_assert(std::same_as); static_assert(std::same_as); - static_assert(std::same_as); + if constexpr (std::is_pointer_v) { + static_assert(std::same_as); + } else { + static_assert(!has_iterator_concept_v); + } return true; } // Standard types. -// These tests depend on implementation details of libc++, -// e.g. that std::array::iterator is a raw pointer type but std::string::iterator is not. -// The Standard does not specify whether iterator_traits::iterator_concept exists for any particular non-pointer type. +// The Standard does not specify whether iterator_traits::iterator_concept exists for any particular non-pointer type, we assume it is present only for pointers. // -static_assert(testWithConcept::iterator, int, std::random_access_iterator_tag, std::contiguous_iterator_tag>()); -static_assert(testConstWithConcept::const_iterator, int, std::random_access_iterator_tag, std::contiguous_iterator_tag>()); -static_assert(testWithoutConcept()); -static_assert(testConstWithoutConcept()); -static_assert(testConstWithConcept()); -static_assert(testConstWithConcept()); -static_assert(testWithoutConcept::iterator, int, std::random_access_iterator_tag>()); -static_assert(testConstWithoutConcept::const_iterator, int, std::random_access_iterator_tag>()); - -static_assert(testWithoutConcept::iterator, int, std::random_access_iterator_tag>()); -static_assert(testConstWithoutConcept::const_iterator, int, std::random_access_iterator_tag>()); -static_assert(testWithoutConcept::iterator, int, std::forward_iterator_tag>()); -static_assert(testConstWithoutConcept::const_iterator, int, std::forward_iterator_tag>()); -static_assert(testWithoutConcept::iterator, int, std::bidirectional_iterator_tag>()); -static_assert(testConstWithoutConcept::const_iterator, int, std::bidirectional_iterator_tag>()); - -static_assert(testWithoutConcept::iterator, std::pair, std::bidirectional_iterator_tag>()); -static_assert(testConstWithoutConcept::const_iterator, std::pair, std::bidirectional_iterator_tag>()); -static_assert(testWithoutConcept::iterator, std::pair, std::bidirectional_iterator_tag>()); -static_assert(testConstWithoutConcept::const_iterator, std::pair, std::bidirectional_iterator_tag>()); - -static_assert(testConstWithoutConcept::iterator, int, std::bidirectional_iterator_tag>()); -static_assert(testConstWithoutConcept::const_iterator, int, std::bidirectional_iterator_tag>()); -static_assert(testConstWithoutConcept::iterator, int, std::bidirectional_iterator_tag>()); -static_assert(testConstWithoutConcept::const_iterator, int, std::bidirectional_iterator_tag>()); - -static_assert(testWithoutConcept::iterator, std::pair, std::forward_iterator_tag>()); -static_assert(testConstWithoutConcept::const_iterator, std::pair, std::forward_iterator_tag>()); -static_assert(testWithoutConcept::local_iterator, std::pair, std::forward_iterator_tag>()); -static_assert(testConstWithoutConcept::const_local_iterator, std::pair, std::forward_iterator_tag>()); -static_assert(testWithoutConcept::iterator, std::pair, std::forward_iterator_tag>()); -static_assert(testConstWithoutConcept::const_iterator, std::pair, std::forward_iterator_tag>()); -static_assert(testWithoutConcept::local_iterator, std::pair, std::forward_iterator_tag>()); -static_assert(testConstWithoutConcept::const_local_iterator, std::pair, std::forward_iterator_tag>()); - -static_assert(testConstWithoutConcept::iterator, int, std::forward_iterator_tag>()); -static_assert(testConstWithoutConcept::const_iterator, int, std::forward_iterator_tag>()); -static_assert(testConstWithoutConcept::local_iterator, int, std::forward_iterator_tag>()); -static_assert(testConstWithoutConcept::const_local_iterator, int, std::forward_iterator_tag>()); -static_assert(testConstWithoutConcept::iterator, int, std::forward_iterator_tag>()); -static_assert(testConstWithoutConcept::const_iterator, int, std::forward_iterator_tag>()); -static_assert(testConstWithoutConcept::local_iterator, int, std::forward_iterator_tag>()); -static_assert(testConstWithoutConcept::const_local_iterator, int, std::forward_iterator_tag>()); - -static_assert(testWithoutConcept, int, std::random_access_iterator_tag>()); +static_assert(test::iterator, int, std::random_access_iterator_tag>()); +static_assert(testConst::const_iterator, int, std::random_access_iterator_tag>()); +static_assert(test()); +static_assert(testConst()); +static_assert(testConst()); +static_assert(testConst()); +static_assert(test::iterator, int, std::random_access_iterator_tag>()); +static_assert(testConst::const_iterator, int, std::random_access_iterator_tag>()); + +static_assert(test::iterator, int, std::random_access_iterator_tag>()); +static_assert(testConst::const_iterator, int, std::random_access_iterator_tag>()); +static_assert(test::iterator, int, std::forward_iterator_tag>()); +static_assert(testConst::const_iterator, int, std::forward_iterator_tag>()); +static_assert(test::iterator, int, std::bidirectional_iterator_tag>()); +static_assert(testConst::const_iterator, int, std::bidirectional_iterator_tag>()); + +static_assert(test::iterator, std::pair, std::bidirectional_iterator_tag>()); +static_assert(testConst::const_iterator, std::pair, std::bidirectional_iterator_tag>()); +static_assert(test::iterator, std::pair, std::bidirectional_iterator_tag>()); +static_assert(testConst::const_iterator, std::pair, std::bidirectional_iterator_tag>()); + +static_assert(testConst::iterator, int, std::bidirectional_iterator_tag>()); +static_assert(testConst::const_iterator, int, std::bidirectional_iterator_tag>()); +static_assert(testConst::iterator, int, std::bidirectional_iterator_tag>()); +static_assert(testConst::const_iterator, int, std::bidirectional_iterator_tag>()); + +#ifdef _MSVC_STL_VERSION +using unordered_iterator_category = std::bidirectional_iterator_tag; +#else // ^^^ MSVC STL / other vvv +using unordered_iterator_category = std::forward_iterator_tag; +#endif // _MSVC_STL_VERSION + +static_assert(test::iterator, std::pair, unordered_iterator_category>()); +static_assert(testConst::const_iterator, std::pair, unordered_iterator_category>()); +static_assert(test::local_iterator, std::pair, unordered_iterator_category>()); +static_assert(testConst::const_local_iterator, std::pair, unordered_iterator_category>()); +static_assert(test::iterator, std::pair, unordered_iterator_category>()); +static_assert(testConst::const_iterator, std::pair, unordered_iterator_category>()); +static_assert(test::local_iterator, std::pair, unordered_iterator_category>()); +static_assert(testConst::const_local_iterator, std::pair, unordered_iterator_category>()); + +static_assert(testConst::iterator, int, unordered_iterator_category>()); +static_assert(testConst::const_iterator, int, unordered_iterator_category>()); +static_assert(testConst::local_iterator, int, unordered_iterator_category>()); +static_assert(testConst::const_local_iterator, int, unordered_iterator_category>()); +static_assert(testConst::iterator, int, unordered_iterator_category>()); +static_assert(testConst::const_iterator, int, unordered_iterator_category>()); +static_assert(testConst::local_iterator, int, unordered_iterator_category>()); +static_assert(testConst::const_local_iterator, int, unordered_iterator_category>()); + +static_assert(test, int, std::random_access_iterator_tag>()); static_assert(testIOIterator>, std::output_iterator_tag>()); static_assert(testIOIterator>, std::output_iterator_tag>()); static_assert(testIOIterator>, std::output_iterator_tag>()); -static_assert(testConstWithoutConcept, int, std::input_iterator_tag>()); +static_assert(testConst, int, std::input_iterator_tag>()); #if !defined(_LIBCPP_HAS_NO_LOCALIZATION) -static_assert(testWithoutConcept, char, long long, char, char*, std::input_iterator_tag>()); -static_assert(testWithoutConcept, int, std::ptrdiff_t, int&&, int*, std::random_access_iterator_tag>()); +// libc++-specific since pointer type is unspecified: +LIBCPP_STATIC_ASSERT(test, char, long long, char, char*, std::input_iterator_tag>()); +static_assert(test, int, std::ptrdiff_t, int&&, int*, std::random_access_iterator_tag>()); static_assert(testIOIterator, std::output_iterator_tag>()); static_assert(testIOIterator, std::output_iterator_tag>()); -static_assert(testConstWithoutConcept()); -static_assert(testConstWithoutConcept()); +static_assert(testConst()); +static_assert(testConst()); #endif // !_LIBCPP_HAS_NO_LOCALIZATION #ifndef _LIBCPP_HAS_NO_FILESYSTEM_LIBRARY -static_assert(testWithoutConcept()); -static_assert(testWithoutConcept()); +static_assert(test()); +static_assert(test()); #endif // Local test iterators. diff --git a/libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.move/iter_move.pass.cpp b/libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.move/iter_move.pass.cpp --- a/libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.move/iter_move.pass.cpp +++ b/libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.move/iter_move.pass.cpp @@ -49,8 +49,8 @@ I base_ = I{}; }; -template -constexpr void unqualified_lookup_move(I first_, I last_, I result_first_, I result_last_) { +template +constexpr void unqualified_lookup_move(I first_, I last_, O result_first_, O result_last_) { auto first = ::check_unqualified_lookup::unqualified_lookup_wrapper{std::move(first_)}; auto last = ::check_unqualified_lookup::unqualified_lookup_wrapper{std::move(last_)}; auto result_first = ::check_unqualified_lookup::unqualified_lookup_wrapper{std::move(result_first_)}; @@ -63,8 +63,8 @@ } } -template -constexpr void lvalue_move(I first_, I last_, I result_first_, I result_last_) { +template +constexpr void lvalue_move(I first_, I last_, O result_first_, O result_last_) { auto first = iterator_wrapper{std::move(first_)}; auto last = ::iterator_wrapper{std::move(last_)}; auto result_first = iterator_wrapper{std::move(result_first_)}; @@ -78,8 +78,8 @@ } } -template -constexpr void rvalue_move(I first_, I last_, I result_first_, I result_last_) { +template +constexpr void rvalue_move(I first_, I last_, O result_first_, O result_last_) { auto first = iterator_wrapper{std::move(first_)}; auto last = iterator_wrapper{std::move(last_)}; auto result_first = iterator_wrapper{std::move(result_first_)}; diff --git a/libcxx/test/std/strings/string.view/string.view.cons/from_iterator_sentinel.pass.cpp b/libcxx/test/std/strings/string.view/string.view.cons/from_iterator_sentinel.pass.cpp --- a/libcxx/test/std/strings/string.view/string.view.cons/from_iterator_sentinel.pass.cpp +++ b/libcxx/test/std/strings/string.view/string.view.cons/from_iterator_sentinel.pass.cpp @@ -25,7 +25,7 @@ template constexpr void test() { auto val = MAKE_STRING_VIEW(CharT, "test"); - auto sv = std::basic_string_view(val.begin(), Sentinel(val.end())); + auto sv = std::basic_string_view(val.data(), Sentinel(val.data() + val.size())); ASSERT_SAME_TYPE(decltype(sv), std::basic_string_view); assert(sv.size() == val.size()); assert(sv.data() == val.data()); @@ -56,7 +56,7 @@ void test_throwing() { auto val = MAKE_STRING_VIEW(CharT, "test"); try { - (void)std::basic_string_view(val.begin(), ThrowingSentinel()); + (void)std::basic_string_view(val.data(), ThrowingSentinel()); assert(false); } catch (int i) { assert(i == 42); @@ -91,4 +91,3 @@ return 0; } - diff --git a/libcxx/test/std/strings/string.view/string.view.deduct/iterator_sentinel.pass.cpp b/libcxx/test/std/strings/string.view/string.view.deduct/iterator_sentinel.pass.cpp --- a/libcxx/test/std/strings/string.view/string.view.deduct/iterator_sentinel.pass.cpp +++ b/libcxx/test/std/strings/string.view/string.view.deduct/iterator_sentinel.pass.cpp @@ -23,7 +23,13 @@ template constexpr void test() { auto val = MAKE_STRING_VIEW(CharT, "test"); - auto sv = std::basic_string_view(val.begin(), Sentinel(val.end())); + auto sv = [&] { + if constexpr (std::same_as) { + return std::basic_string_view(val.begin(), Sentinel(val.end())); + } else { + return std::basic_string_view(val.data(), Sentinel(val.data() + val.size())); + } + }(); ASSERT_SAME_TYPE(decltype(sv), std::basic_string_view); assert(sv.size() == val.size()); assert(sv.data() == val.data()); @@ -46,4 +52,3 @@ return 0; } - diff --git a/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/advance_to.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/advance_to.pass.cpp --- a/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/advance_to.pass.cpp +++ b/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/advance_to.pass.cpp @@ -26,10 +26,10 @@ std::basic_format_parse_context context(fmt); context.advance_to(context.begin() + 1); - assert(context.begin() == &fmt[1]); + assert(std::to_address(context.begin()) == &fmt[1]); context.advance_to(context.begin() + 1); - assert(context.begin() == &fmt[2]); + assert(std::to_address(context.begin()) == &fmt[2]); context.advance_to(context.begin() + 1); assert(context.begin() == context.end()); diff --git a/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/begin.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/begin.pass.cpp --- a/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/begin.pass.cpp +++ b/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/begin.pass.cpp @@ -24,7 +24,7 @@ constexpr void test(const CharT* fmt) { { std::basic_format_parse_context context(fmt); - assert(context.begin() == &fmt[0]); + assert(std::to_address(context.begin()) == &fmt[0]); ASSERT_NOEXCEPT(context.begin()); } { diff --git a/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/ctor.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/ctor.pass.cpp --- a/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/ctor.pass.cpp +++ b/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/ctor.pass.cpp @@ -47,8 +47,8 @@ { std::basic_format_parse_context context(fmt); - assert(context.begin() == &fmt[0]); - assert(context.end() == &fmt[3]); + assert(std::to_address(context.begin()) == &fmt[0]); + assert(std::to_address(context.end()) == &fmt[3]); } { std::basic_string_view view{fmt}; diff --git a/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/end.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/end.pass.cpp --- a/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/end.pass.cpp +++ b/libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/end.pass.cpp @@ -24,7 +24,7 @@ constexpr void test(const CharT* fmt) { { std::basic_format_parse_context context(fmt); - assert(context.end() == &fmt[3]); + assert(std::to_address(context.end()) == &fmt[3]); ASSERT_NOEXCEPT(context.end()); } { diff --git a/libcxx/test/support/test_iterators.h b/libcxx/test/support/test_iterators.h --- a/libcxx/test/support/test_iterators.h +++ b/libcxx/test/support/test_iterators.h @@ -356,8 +356,6 @@ template class contiguous_iterator { - static_assert(std::is_pointer_v, "Things probably break in this case"); - It it_; template friend class contiguous_iterator; @@ -367,7 +365,7 @@ typedef typename std::iterator_traits::difference_type difference_type; typedef It pointer; typedef typename std::iterator_traits::reference reference; - typedef typename std::remove_pointer::type element_type; + typedef typename std::remove_reference::type element_type; TEST_CONSTEXPR_CXX14 It base() const {return it_;}