Debian Codegraph @

clang/test/SemaCXX/cxx2b-deducing-this-constexpr.cpp

raw
1 // RUN: %clang_cc1 -fsyntax-only -std=c++2b %s -verify
2 // RUN: %clang_cc1 -fsyntax-only -std=c++2b %s -verify -fexperimental-new-constant-interpreter
3 // expected-no-diagnostics
4
5 template <typename Base>
6 struct Wrap : Base {
7
8 };
9
10 struct S {
11 constexpr int f(this const S&) {
12 return 42;
13 }
14 constexpr int f(this const S&, auto&&... args) {
15 return (args + ... + 0);
16 }
17 constexpr int operator[](this const S&) {
18 return 42;
19 }
20 constexpr int operator[](this const S& self, int i) {
21 return i + self.base;
22 }
23 constexpr int operator()(this const S&) {
24 return 42;
25 }
26 constexpr int operator()(this const S& self, int i) {
27 return self.base + i;
28 }
29 constexpr bool operator==(this const S& self, auto && test) {
30 return self.base == test;
31 };
32 constexpr int operator*(this const S& self) {
33 return self.base + 22;
34 };
35 constexpr operator Wrap<S> (this const S& self) {
36 return Wrap<S>{self};
37 };
38 constexpr int operator <<(this Wrap<S> self, int i) {
39 return self.base+i;
40 }
41
42 int base = 20;
43 };
44
45 consteval void test() {
46 constexpr S s;
47 static_assert(s.f() == 42);
48 static_assert(s[] == 42);
49 static_assert(s[22] == 42);
50 static_assert(s.f() == 42);
51 static_assert(s() == 42);
52 static_assert(s(22) == 42);
53 static_assert(s == 20);
54 static_assert(s != 0);
55 static_assert(*s == 42);
56 static_assert((s << 11) == 31);
57 }
58
59 namespace GH68070 {
60
61 constexpr auto f = [x = 3]<typename Self>(this Self&& self) {
62 return x;
63 };
64
65 auto g = [x = 3]<typename Self>(this Self&& self) {
66 return x;
67 };
68
69 int test() {
70 constexpr int a = f();
71 static_assert(a == 3);
72 return f() + g();
73 }
74
75 }