| 1 |
// RUN: %clang_cc1 -std=c++23 -verify -fsyntax-only %s |
| 2 |
// This test case came up in the review of |
| 3 |
// https://reviews.llvm.org/D159126 |
| 4 |
// when transforming `this` within a |
| 5 |
// requires expression, we need to make sure |
| 6 |
// the type of this (and its qualifiers) is respected. |
| 7 |
|
| 8 |
// expected-no-diagnostics |
| 9 |
namespace D159126 { |
| 10 |
|
| 11 |
template <class _Tp> |
| 12 |
concept __member_begin = requires(_Tp __t) { |
| 13 |
__t.begin(); |
| 14 |
}; |
| 15 |
|
| 16 |
struct { |
| 17 |
template <class _Tp> |
| 18 |
requires __member_begin<_Tp> |
| 19 |
auto operator()(_Tp &&) {} |
| 20 |
} inline begin; |
| 21 |
|
| 22 |
template <class> |
| 23 |
concept range = requires { |
| 24 |
begin; |
| 25 |
}; |
| 26 |
|
| 27 |
template <class _Tp> |
| 28 |
concept __can_compare_begin = requires(_Tp __t) { |
| 29 |
begin(__t); |
| 30 |
}; |
| 31 |
|
| 32 |
struct { |
| 33 |
template <__can_compare_begin _Tp> void operator()(_Tp &&); |
| 34 |
} empty; |
| 35 |
|
| 36 |
template <range _Rp> struct owning_view { |
| 37 |
_Rp __r_; |
| 38 |
public: |
| 39 |
void empty() const requires requires { empty(__r_); }; |
| 40 |
}; |
| 41 |
|
| 42 |
template <class T> |
| 43 |
concept HasEmpty = requires(T t) { |
| 44 |
t.empty(); |
| 45 |
}; |
| 46 |
|
| 47 |
struct ComparableIters { |
| 48 |
void begin(); |
| 49 |
}; |
| 50 |
|
| 51 |
static_assert(HasEmpty<owning_view<ComparableIters&>>); |
| 52 |
static_assert(HasEmpty<owning_view<ComparableIters&&>>); |
| 53 |
static_assert(!HasEmpty<owning_view<const ComparableIters&>>); |
| 54 |
static_assert(!HasEmpty<owning_view<const ComparableIters&&>>); |
| 55 |
|
| 56 |
} |