Debian Codegraph @

clang/test/CodeCompletion/cpp23-explicit-object.cpp

raw
1 struct A {
2 void foo(this auto&& self, int arg);
3 void bar(this A self, int arg);
4 };
5
6 int func1() {
7 A a {};
8 a.
9 }
10 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-2):5 -std=c++23 %s | FileCheck -check-prefix=CHECK-CC1 %s
11 // CHECK-CC1: COMPLETION: A : A::
12 // CHECK-NEXT-CC1: COMPLETION: bar : [#void#]bar(<#int arg#>)
13 // CHECK-NEXT-CC1: COMPLETION: foo : [#void#]foo(<#int arg#>)
14 // CHECK-NEXT-CC1: COMPLETION: operator= : [#A &#]operator=(<#const A &#>)
15 // CHECK-NEXT-CC1: COMPLETION: operator= : [#A &#]operator=(<#A &&#>)
16 // CHECK-NEXT-CC1: COMPLETION: ~A : [#void#]~A()
17
18 struct B {
19 template <typename T>
20 void foo(this T&& self, int arg);
21 };
22
23 int func2() {
24 B b {};
25 b.foo();
26 }
27 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-2):9 -std=c++23 %s | FileCheck -check-prefix=CHECK-CC2 %s
28 // CHECK-CC2: OVERLOAD: [#void#]foo(int arg)
29
30 // TODO: llvm/llvm-project/146649
31 // This is incorrect behavior. Correct Result should be a variant of,
32 // CC3: should be something like [#void#]foo(<#A self#>, <#int arg#>)
33 // CC4: should be something like [#void#]bar(<#A self#>, <#int arg#>)
34 int func3() {
35 (&A::foo)
36 (&A::bar)
37 }
38 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-3):10 -std=c++23 %s | FileCheck -check-prefix=CHECK-CC3 %s
39 // CHECK-CC3: COMPLETION: foo : [#void#]foo<<#class self:auto#>>(<#int arg#>)
40 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-4):10 -std=c++23 %s | FileCheck -check-prefix=CHECK-CC4 %s
41 // CHECK-CC4: COMPLETION: bar : [#void#]bar(<#int arg#>)
42
43 int func4() {
44 // TODO (&A::foo)(
45 (&A::bar)()
46 }
47 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-2):13 -std=c++23 %s | FileCheck -check-prefix=CHECK-CC5 %s
48 // CHECK-CC5: OVERLOAD: [#void#](<#A#>, int)
49
50 struct C {
51 int member {};
52 int memberFnA(int a);
53 int memberFnA(this C&, float a);
54
55 void foo(this C& self) {
56 // Should not offer any members here, since
57 // it needs to be referenced through `self`.
58 mem
59 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-1):8 -std=c++23 %s | FileCheck --allow-empty %s
60 // CHECK-NOT: COMPLETION: member : [#int#]member
61 // CHECK-NOT: COMPLETION: memberFnA : [#int#]memberFnA(<#int a#>)
62 // CHECK-NOT: COMPLETION: memberFnA : [#int#]memberFnA(<#float a#>)
63 }
64 void bar(this C& self) {
65 // should offer all results
66 self.mem
67 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-1):13 -std=c++23 %s | FileCheck -check-prefix=CHECK-CC6 %s
68 // CHECK-CC6: COMPLETION: member : [#int#]member
69 // CHECK-CC6: COMPLETION: memberFnA : [#int#]memberFnA(<#int a#>)
70 // CHECK-CC6: COMPLETION: memberFnA : [#int#]memberFnA(<#float a#>)
71 }
72 void baz(this C& self) {
73 [&]() {
74 // Should not offer any results
75 mem
76 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-1):10 -std=c++23 %s | FileCheck --allow-empty %s
77 // CHECK-NOT: COMPLETION: member : [#int#]member
78 // CHECK-NOT: COMPLETION: memberFnA : [#int#]memberFnA(<#int a#>)
79 // CHECK-NOT: COMPLETION: memberFnA : [#int#]memberFnA(<#float a#>)
80 }();
81 }
82 };
83
84
85 struct S {
86 void foo1(int a);
87 void foo2(int a) const;
88 void foo2(this const S& self, float a);
89 void foo3(this const S& self, int a);
90 void foo4(this S& self, int a);
91 };
92
93 void S::foo1(int a) {
94 this->;
95 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-1):9 -std=c++23 %s | FileCheck -check-prefix=CHECK-CC7 %s
96 // CHECK-CC7: COMPLETION: foo1 : [#void#]foo1(<#int a#>)
97 // CHECK-CC7: COMPLETION: foo2 : [#void#]foo2(<#int a#>)[# const#]
98 // CHECK-CC7: COMPLETION: foo2 : [#void#]foo2(<#float a#>)[# const#]
99 // CHECK-CC7: COMPLETION: foo3 : [#void#]foo3(<#int a#>)[# const#]
100 // CHECK-CC7: COMPLETION: foo4 : [#void#]foo4(<#int a#>)
101 }
102
103 void S::foo2(int a) const {
104 this->;
105 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-1):9 -std=c++23 %s | FileCheck -check-prefix=CHECK-CC8 %s
106 // CHECK-CC8: COMPLETION: foo2 : [#void#]foo2(<#int a#>)[# const#]
107 // CHECK-CC8: COMPLETION: foo2 : [#void#]foo2(<#float a#>)[# const#]
108 // CHECK-CC8: COMPLETION: foo3 : [#void#]foo3(<#int a#>)[# const#]
109 }
110
111 void S::foo3(this const S& self, int a) {
112 self.;
113 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-1):8 -std=c++23 %s | FileCheck -check-prefix=CHECK-CC9 %s
114 // CHECK-CC9: COMPLETION: foo2 : [#void#]foo2(<#int a#>)[# const#]
115 // CHECK-CC9: COMPLETION: foo2 : [#void#]foo2(<#float a#>)[# const#]
116 // CHECK-CC9: COMPLETION: foo3 : [#void#]foo3(<#int a#>)[# const#]
117 }
118
119 void S::foo4(this S& self, int a) {
120 self.;
121 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-1):8 -std=c++23 %s | FileCheck -check-prefix=CHECK-CC10 %s
122 // CHECK-CC10: COMPLETION: foo1 : [#void#]foo1(<#int a#>)
123 // CHECK-CC10: COMPLETION: foo2 : [#void#]foo2(<#int a#>)[# const#]
124 // CHECK-CC10: COMPLETION: foo2 : [#void#]foo2(<#float a#>)[# const#]
125 // CHECK-CC10: COMPLETION: foo3 : [#void#]foo3(<#int a#>)[# const#]
126 // CHECK-CC10: COMPLETION: foo4 : [#void#]foo4(<#int a#>)
127 }
128
129 void test1(S s) {
130 s.;
131 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-1):5 -std=c++23 %s | FileCheck -check-prefix=CHECK-CC11 %s
132 // CHECK-CC11: COMPLETION: foo1 : [#void#]foo1(<#int a#>)
133 // CHECK-CC11: COMPLETION: foo2 : [#void#]foo2(<#int a#>)[# const#]
134 // CHECK-CC11: COMPLETION: foo2 : [#void#]foo2(<#float a#>)[# const#]
135 // CHECK-CC11: COMPLETION: foo3 : [#void#]foo3(<#int a#>)[# const#]
136 // CHECK-CC11: COMPLETION: foo4 : [#void#]foo4(<#int a#>)
137 }
138
139 void test2(const S s) {
140 s.;
141 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-1):5 -std=c++23 %s | FileCheck -check-prefix=CHECK-CC12 %s
142 // CHECK-CC12: COMPLETION: foo2 : [#void#]foo2(<#int a#>)[# const#]
143 // CHECK-CC12: COMPLETION: foo2 : [#void#]foo2(<#float a#>)[# const#]
144 // CHECK-CC12: COMPLETION: foo3 : [#void#]foo3(<#int a#>)[# const#]
145 }
146
147 void test3(S s) {
148 s.foo2();
149 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-1):10 -std=c++23 %s | FileCheck -check-prefix=CHECK-CC13 %s
150 // CHECK-CC13: OVERLOAD: [#void#]foo2(<#int a#>)
151 // CHECK-CC13: OVERLOAD: [#void#]foo2(float a)
152 // TODO: foo2 should be OVERLOAD: [#void#]foo2(<#float a#>)
153 }