[RISCV] Add shrinkwrap test cases showing gaps in current impl
[llvm-project.git] / clang / test / CodeGenCXX / cxx2b-static-subscript-operator.cpp
blob5d8258978c50d57fa948913d9a06a43e5fb9d2b7
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
4 struct Functor {
5 static int operator[](int x, int y) {
6 return x + y;
8 };
10 Functor GetAFunctor() {
11 return {};
14 void call_static_subscript_operator() {
15 Functor f;
16 f[101, 102];
17 f.operator[](201, 202);
18 Functor{}[301, 302];
19 Functor::operator[](401, 402);
20 GetAFunctor()[501, 502];
23 // CHECK: define {{.*}}call_static_subscript_operator{{.*}}
24 // CHECK-NEXT: entry:
25 // CHECK: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 101, i32 noundef 102)
26 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 201, i32 noundef 202)
27 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 301, i32 noundef 302)
28 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 401, i32 noundef 402)
29 // CHECK: {{.*}}call {{.*}}GetAFunctor{{.*}}()
30 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 501, i32 noundef 502)
31 // CHECK-NEXT: ret void
32 // CHECK-NEXT: }
34 struct FunctorConsteval {
35 consteval static int operator[](int x, int y) {
36 return x + y;
40 struct FunctorConstexpr {
41 constexpr static int operator[](int x, int y) {
42 return x + y;
46 void test_consteval_constexpr() {
47 int x = 0;
48 int y = FunctorConstexpr{}[x, 2];
49 constexpr int z1 = FunctorConsteval{}[2, 2];
50 constexpr int z2 = FunctorConstexpr{}[2, 2];
52 static_assert(z1 == 4);
53 static_assert(z2 == 4);
56 template <class T>
57 struct DepFunctor {
58 static int operator[](T t) {
59 return int(t);
63 void test_dep_functors() {
64 int x = DepFunctor<float>{}[1.0f];
65 int y = DepFunctor<bool>{}[true];
68 // CHECK: define {{.*}}test_dep_functors{{.*}}
69 // CHECK-NEXT: entry:
70 // CHECK: {{.*}} = call noundef i32 {{.*}}DepFunctor{{.*}}(float noundef 1.000000e+00)
71 // CHECK: {{.*}} = call noundef i32 {{.*}}DepFunctor{{.*}}(i1 noundef zeroext true)
72 // CHECK: ret void
73 // CHECK-NEXT: }