https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108393
Bug ID: 108393
Summary: circular concept false-positive
Product: gcc
Version: 12.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: nikolasklauser at berlin dot de
Target Milestone: ---
GCC errors on the reproducer below with
./equality_comparable.cpp: In substitution of 'template<class _Iter> requires
C<_Iter> constexpr bool operator==(unreachable_sentinel_t, const _Iter&) [with
_Iter = S<unreachable_sentinel_t>]':
./equality_comparable.cpp:6:41: required by substitution of 'template<class
T> requires requires(T __t, T __u) {__t == __u;} struct iterator_traits<T>
[with T = S<unreachable_sentinel_t>]'
./equality_comparable.cpp:11:33: required from here
./equality_comparable.cpp:11:9: required for the satisfaction of 'C<_Iter>'
[with _Iter = S<unreachable_sentinel_t>]
./equality_comparable.cpp:11:13: in requirements [with T =
S<unreachable_sentinel_t>]
./equality_comparable.cpp:11:13: error: satisfaction of atomic constraint
'requires{typename iterator_traits<T>::A;} [with T = T]' depends on itself
11 | concept C = requires { typename iterator_traits<T>::A; };
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./equality_comparable.cpp: In substitution of 'template<class _Iter> requires
C<_Iter> constexpr bool operator==(unreachable_sentinel_t, const _Iter&) [with
_Iter = S<unreachable_sentinel_t>]':
./equality_comparable.cpp:6:41: required by substitution of 'template<class
T> requires requires(T __t, T __u) {__t == __u;} struct iterator_traits<T>
[with T = S<unreachable_sentinel_t>]'
./equality_comparable.cpp:11:33: required from here
./equality_comparable.cpp:11:9: required for the satisfaction of 'C<_Iter>'
[with _Iter = S<unreachable_sentinel_t>]
./equality_comparable.cpp:11:13: in requirements [with T =
S<unreachable_sentinel_t>]
./equality_comparable.cpp:11:13: error: satisfaction of atomic constraint
'requires{typename iterator_traits<T>::A;} [with T = T]' depends on itself
But AFAICT this code should compile just fine.
iterator_traits<unreachable_sentinel_t> should never get instantiated and I
don't see another way this would result in a self-reference.
reproducer (Godbolt: https://godbolt.org/z/cfP5fqcMc):
template<class>
struct iterator_traits
{};
template<class T>
requires requires(T __t, T __u) { __t == __u; }
struct iterator_traits<T>
{};
template<class T>
concept C = requires { typename iterator_traits<T>::A; };
struct unreachable_sentinel_t
{
template<C _Iter>
friend constexpr bool operator==(unreachable_sentinel_t, const _Iter&)
noexcept;
};
template<class T>
struct S
{};
static_assert(!C<S<unreachable_sentinel_t>>);