[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGenCXX / cxx2b-static-subscript-operator.cpp
blob3d8957698f5a7d8dfaedb450ea8f59758d920921
1 // RUN: %clang_cc1 -std=c++2b %s -emit-llvm -triple x86_64-linux -o - | FileCheck %s
2 // RUN: %clang_cc1 -std=c++2b %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 void call_static_subscript_operator() {
11 Functor f;
12 f[101, 102];
13 f.operator[](201, 202);
14 Functor{}[301, 302];
15 Functor::operator[](401, 402);
18 // CHECK: define {{.*}}call_static_subscript_operator{{.*}}
19 // CHECK-NEXT: entry:
20 // CHECK: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 101, i32 noundef 102)
21 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 201, i32 noundef 202)
22 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 301, i32 noundef 302)
23 // CHECK-NEXT: {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 401, i32 noundef 402)
24 // CHECK-NEXT: ret void
25 // CHECK-NEXT: }
27 struct FunctorConsteval {
28 consteval static int operator[](int x, int y) {
29 return x + y;
33 struct FunctorConstexpr {
34 constexpr static int operator[](int x, int y) {
35 return x + y;
39 void test_consteval_constexpr() {
40 int x = 0;
41 int y = FunctorConstexpr{}[x, 2];
42 constexpr int z1 = FunctorConsteval{}[2, 2];
43 constexpr int z2 = FunctorConstexpr{}[2, 2];
45 static_assert(z1 == 4);
46 static_assert(z2 == 4);
49 template <class T>
50 struct DepFunctor {
51 static int operator[](T t) {
52 return int(t);
56 void test_dep_functors() {
57 int x = DepFunctor<float>{}[1.0f];
58 int y = DepFunctor<bool>{}[true];
61 // CHECK: define {{.*}}test_dep_functors{{.*}}
62 // CHECK-NEXT: entry:
63 // CHECK: %call = call noundef i32 {{.*}}DepFunctor{{.*}}(float noundef 1.000000e+00)
64 // CHECK: %call1 = call noundef i32 {{.*}}DepFunctor{{.*}}(i1 noundef zeroext true)
65 // CHECK: ret void
66 // CHECK-NEXT: }