[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / this-type-deduction-concept.cpp
blob7f578440befdb234e938d948d69d34efeb317e74
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.
8 // expected-no-diagnostics
9 namespace D159126 {
11 template <class _Tp>
12 concept __member_begin = requires(_Tp __t) {
13 __t.begin();
16 struct {
17 template <class _Tp>
18 requires __member_begin<_Tp>
19 auto operator()(_Tp &&) {}
20 } inline begin;
22 template <class>
23 concept range = requires {
24 begin;
27 template <class _Tp>
28 concept __can_compare_begin = requires(_Tp __t) {
29 begin(__t);
32 struct {
33 template <__can_compare_begin _Tp> void operator()(_Tp &&);
34 } empty;
36 template <range _Rp> struct owning_view {
37 _Rp __r_;
38 public:
39 void empty() const requires requires { empty(__r_); };
42 template <class T>
43 concept HasEmpty = requires(T t) {
44 t.empty();
47 struct ComparableIters {
48 void begin();
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&&>>);