diff --git a/libcxx/include/__iterator/concepts.h b/libcxx/include/__iterator/concepts.h index 27474a37293fd3..531acdf0a5b2cb 100644 --- a/libcxx/include/__iterator/concepts.h +++ b/libcxx/include/__iterator/concepts.h @@ -171,7 +171,6 @@ concept contiguous_iterator = derived_from<_ITER_CONCEPT<_Ip>, contiguous_iterator_tag> && is_lvalue_reference_v> && same_as, remove_cvref_t>> && - (is_pointer_v<_Ip> || requires { sizeof(__pointer_traits_element_type<_Ip>); }) && requires(const _Ip& __i) { { _VSTD::to_address(__i) } -> same_as>>; }; diff --git a/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.compile.pass.cpp b/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.compile.pass.cpp index e5d24f430297a4..ba75ce2a9b52c9 100644 --- a/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.compile.pass.cpp +++ b/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.compile.pass.cpp @@ -101,9 +101,10 @@ static_assert(!std::contiguous_iterator); struct wrong_iter_reference_t { typedef std::contiguous_iterator_tag iterator_category; typedef short value_type; + typedef short element_type; typedef std::ptrdiff_t difference_type; - typedef int* pointer; - typedef short& reference; + typedef short* pointer; + typedef int& reference; typedef wrong_iter_reference_t self; wrong_iter_reference_t(); @@ -132,40 +133,6 @@ struct wrong_iter_reference_t { static_assert(std::random_access_iterator); static_assert(!std::contiguous_iterator); -struct no_element_type { - typedef std::contiguous_iterator_tag iterator_category; - typedef int value_type; - typedef std::ptrdiff_t difference_type; - typedef int* pointer; - typedef int& reference; - typedef no_element_type self; - - no_element_type(); - - reference operator*() const; - pointer operator->() const; - auto operator<=>(const self&) const = default; - - self& operator++(); - self operator++(int); - - self& operator--(); - self operator--(int); - - self& operator+=(difference_type n); - self operator+(difference_type n) const; - friend self operator+(difference_type n, self x); - - self& operator-=(difference_type n); - self operator-(difference_type n) const; - difference_type operator-(const self& n) const; - - reference operator[](difference_type n) const; -}; - -static_assert(std::random_access_iterator); -static_assert(!std::contiguous_iterator); - struct to_address_wrong_return_type { typedef std::contiguous_iterator_tag iterator_category; typedef int value_type; diff --git a/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.verify.cpp b/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.verify.cpp new file mode 100644 index 00000000000000..189a00d7975a81 --- /dev/null +++ b/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.verify.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// UNSUPPORTED: libcpp-no-concepts +// REQUIRES: libc++ + +// This test checks that std::contiguous_iterator uses std::to_address, which is not SFINAE-friendly +// when the type is missing the `T::element_type` typedef. + +#include + +#include +#include + +struct no_element_type { + typedef std::contiguous_iterator_tag iterator_category; + typedef int value_type; + typedef std::ptrdiff_t difference_type; + typedef int* pointer; + typedef int& reference; + typedef no_element_type self; + + no_element_type(); + + reference operator*() const; + pointer operator->() const; + auto operator<=>(const self&) const = default; + + self& operator++(); + self operator++(int); + + self& operator--(); + self operator--(int); + + self& operator+=(difference_type n); + self operator+(difference_type n) const; + friend self operator+(difference_type n, self x); + + self& operator-=(difference_type n); + self operator-(difference_type n) const; + difference_type operator-(const self& n) const; + + reference operator[](difference_type n) const; +}; + +void test() { + (void) std::contiguous_iterator; + // expected-error@*:* {{implicit instantiation of undefined template}} + // expected-note@*:* {{to_address}} +}