1 // RUN: %clang_cc1 -std=c++23 %s -emit-llvm -triple x86_64-linux -o - | FileCheck %s
2 // RUN: %clang_cc1 -std=c++23 %s -emit-llvm -triple x86_64-windows-msvc -o - | FileCheck %s
5 static int operator()(int x
, int y
) {
11 return [](int x
, int y
) static {
16 void CallsTheLambda() {
20 // CHECK: define {{.*}}CallsTheLambda{{.*}}
22 // CHECK: {{.*}}call {{.*}}GetALambda{{.*}}()
23 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}(i32 noundef 1, i32 noundef 2)
24 // CHECK-NEXT: ret void
27 Functor
GetAFunctor() {
31 void call_static_call_operator() {
34 f
.operator()(201, 202);
36 Functor::operator()(401, 402);
37 GetAFunctor()(501, 502);
40 // CHECK: define {{.*}}call_static_call_operator{{.*}}
42 // CHECK: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 101, i32 noundef 102)
43 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 201, i32 noundef 202)
44 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 301, i32 noundef 302)
45 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 401, i32 noundef 402)
46 // CHECK: {{.*}}call {{.*}}GetAFunctor{{.*}}()
47 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 501, i32 noundef 502)
48 // CHECK-NEXT: ret void
51 struct FunctorConsteval
{
52 consteval
static int operator()(int x
, int y
) {
57 struct FunctorConstexpr
{
58 constexpr static int operator()(int x
, int y
) {
63 constexpr auto my_lambda
= []() constexpr {
67 void test_consteval_constexpr() {
69 int y
= FunctorConstexpr
{}(x
, 2);
70 constexpr int z1
= FunctorConsteval
{}(2, 2);
71 constexpr int z2
= FunctorConstexpr
{}(2, 2);
73 static_assert(z1
== 4);
74 static_assert(z2
== 4);
76 constexpr auto my_lambda
= []() constexpr static {
79 constexpr int (*f
)(void) = my_lambda
;
80 constexpr int k
= f();
81 static_assert(k
== 3);
86 static int operator()(T t
) {
93 return [](T t
) static -> int {
99 return [](auto t
) static -> int {
104 void test_dep_functors() {
105 int x
= DepFunctor
<float>{}(1.0f
);
106 int y
= DepFunctor
<bool>{}(true);
108 int a
= dep_lambda1
<float>()(1.0f
);
109 int b
= dep_lambda1
<bool>()(true);
111 int h
= dep_lambda2()(1.0f
);
112 int i
= dep_lambda2()(true);
115 // CHECK: define {{.*}}test_dep_functors{{.*}}
116 // CHECK-NEXT: entry:
117 // CHECK: {{.*}} = call noundef i32 {{.*}}DepFunctor{{.*}}(float noundef 1.000000e+00)
118 // CHECK: {{.*}} = call noundef i32 {{.*}}DepFunctor{{.*}}(i1 noundef zeroext true)
119 // CHECK: {{.*}}call {{.*}}dep_lambda1{{.*}}()
120 // CHECK: {{.*}} = call noundef i32 {{.*}}dep_lambda1{{.*}}(float noundef 1.000000e+00)
121 // CHECK: {{.*}}call {{.*}}dep_lambda1{{.*}}()
122 // CHECK: {{.*}} = call noundef i32 {{.*}}dep_lambda1{{.*}}(i1 noundef zeroext true)
123 // CHECK: {{.*}}call {{.*}}dep_lambda2{{.*}}()
124 // CHECK: {{.*}} = call noundef i32 {{.*}}dep_lambda2{{.*}}(float noundef 1.000000e+00)
125 // CHECK: {{.*}}call {{.*}}dep_lambda2{{.*}}()
126 // CHECK: {{.*}} = call noundef i32 {{.*}}dep_lambda2{{.*}}(i1 noundef zeroext true)
132 static constexpr auto operator()() { return 4; };
135 constexpr operator P
*() { return operator(); }
141 // Checks that overload resolution works.