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 @@ -67,155 +67,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(TEST_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 // !TEST_HAS_NO_LOCALIZATION #ifndef TEST_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 @@ -51,8 +51,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(It first_, It last_, Out result_first_, Out 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_)}; @@ -65,8 +65,8 @@ } } -template -constexpr void lvalue_move(I first_, I last_, I result_first_, I result_last_) { +template +constexpr void lvalue_move(It first_, It last_, Out result_first_, Out 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_)}; @@ -80,8 +80,8 @@ } } -template -constexpr void rvalue_move(I first_, I last_, I result_first_, I result_last_) { +template +constexpr void rvalue_move(It first_, It last_, Out result_first_, Out 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 @@ -20,25 +20,33 @@ #include "make_string.h" #include "test_iterators.h" -template -constexpr void test() { - auto val = MAKE_STRING_VIEW(CharT, "test"); - auto sv = std::basic_string_view(val.begin(), Sentinel(val.end())); - ASSERT_SAME_TYPE(decltype(sv), std::basic_string_view); - assert(sv.size() == val.size()); +template +constexpr void test_construction(std::basic_string_view val) { + auto sv = std::basic_string_view(It(val.data()), Sentinel(It(val.data() + val.size()))); assert(sv.data() == val.data()); + assert(sv.size() == val.size()); +} + +template +constexpr void test_with_char() { + const auto val = MAKE_STRING_VIEW(CharT, "test"); + test_construction(val); + test_construction(val); + test_construction(val); + test_construction>(val); + test_construction, contiguous_iterator>(val); + test_construction, sized_sentinel>>(val); } constexpr bool test() { - test(); + test_with_char(); #ifndef TEST_HAS_NO_WIDE_CHARACTERS - test(); + test_with_char(); #endif - test(); - test(); - test(); - test(); - test>(); + test_with_char(); + test_with_char(); + test_with_char(); + return true; } @@ -54,7 +62,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); @@ -89,4 +97,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 @@ -20,25 +20,33 @@ #include "test_macros.h" #include "test_iterators.h" -template -constexpr void test() { - auto val = MAKE_STRING_VIEW(CharT, "test"); - auto sv = std::basic_string_view(val.begin(), Sentinel(val.end())); +template +constexpr void test_deduction(std::basic_string_view val) { + auto sv = std::basic_string_view(It(val.data()), Sentinel(It(val.data() + val.size()))); ASSERT_SAME_TYPE(decltype(sv), std::basic_string_view); - assert(sv.size() == val.size()); assert(sv.data() == val.data()); + assert(sv.size() == val.size()); +} + +template +constexpr void test_with_char() { + const auto val = MAKE_STRING_VIEW(CharT, "test"); + test_deduction(val); + test_deduction(val); + test_deduction(val); + test_deduction>(val); + test_deduction, contiguous_iterator>(val); + test_deduction, sized_sentinel>>(val); } constexpr void test() { - test(); + test_with_char(); #ifndef TEST_HAS_NO_WIDE_CHARACTERS - test(); + test_with_char(); #endif - test(); - test(); - test(); - test(); - test>(); + test_with_char(); + test_with_char(); + test_with_char(); } int main(int, char**) { @@ -46,4 +54,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()); } {