[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / ms-property.cpp
blob168987b2462233007b171db09bbf8eca95d98170
1 // RUN: %clang_cc1 -ast-print -verify -triple=x86_64-pc-win32 -fms-compatibility %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fms-compatibility -emit-pch -o %t %s
3 // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fms-compatibility -include-pch %t -verify %s -ast-print -o - | FileCheck %s
4 // expected-no-diagnostics
6 #ifndef HEADER
7 #define HEADER
9 class Test1 {
10 private:
11 int x_;
13 public:
14 Test1(int x) : x_(x) {}
15 __declspec(property(get = get_x)) int X;
16 int get_x() const { return x_; }
17 static Test1 *GetTest1() { return new Test1(10); }
20 class S {
21 public:
22 __declspec(property(get=GetX,put=PutX)) int x[];
23 int GetX(int i, int j) { return i+j; }
24 void PutX(int i, int j, int k) { j = i = k; }
25 __declspec(property(get=GetY,put=PutY)) int y[][];
26 int GetY(int i, int j) { return i+j; }
27 void PutY(int i, int j, int k) { j = i = k; }
28 __declspec(property(get=GetZ,put=PutZ)) int z[][][];
29 int GetZ(int i, int j, int k);
30 void PutZ(int i, int j, int k, int val);
33 template <typename T>
34 class St {
35 public:
36 __declspec(property(get=GetX,put=PutX)) T x[];
37 T GetX(T i, T j) { return i+j; }
38 T PutX(T i, T j, T k) { return j = i = k; }
39 __declspec(property(get=GetY,put=PutY)) T y[][];
40 T GetY(T i, T j) { return i+j; }
41 T PutY(T i, T j, T k) { return j = i = k; }
42 __declspec(property(get=GetZ,put=PutZ)) T z[][][];
43 T GetZ(T i, T j, T k) { return i+j+k; }
44 T PutZ(T i, T j, T k, T v) { return j = i = k = v; }
45 ~St() { x[0][0] = x[1][1]; y[0][0] = x[1][1]; z[0][1][2] = z[2][1][0]; }
48 // CHECK: this->x[0][0] = this->x[1][1];
49 // CHECK: this->y[0][0] = this->x[1][1];
50 // CHECK: this->z[0][1][2] = this->z[2][1][0];
51 // CHECK: this->x[0][0] = this->x[1][1];
52 // CHECK: this->y[0][0] = this->x[1][1];
53 // CHECK: this->z[0][1][2] = this->z[2][1][0];
55 // CHECK-LABEL: main
56 int main(int argc, char **argv) {
57 S *p1 = 0;
58 St<float> *p2 = 0;
59 // CHECK: St<int> a;
60 St<int> a;
61 // CHECK-NEXT: int j = (p1->x)[223][11];
62 int j = (p1->x)[223][11];
63 // CHECK-NEXT: (p1->x[23])[1] = j;
64 (p1->x[23])[1] = j;
65 // CHECK-NEXT: int k = (p1->y)[223][11];
66 int k = (p1->y)[223][11];
67 // CHECK-NEXT: (p1->y[23])[1] = k;
68 (p1->y[23])[1] = k;
69 // CHECK-NEXT: int k3 = p1->z[1][2][3];
70 int k3 = p1->z[1][2][3];
71 // CHECK-NEXT: p1->z[0][2][1] = k3;
72 p1->z[0][2][1] = k3;
73 // CHECK-NEXT: float j1 = (p2->x[223][11]);
74 float j1 = (p2->x[223][11]);
75 // CHECK-NEXT: ((p2->x)[23])[1] = j1;
76 ((p2->x)[23])[1] = j1;
77 // CHECK-NEXT: float k1 = (p2->y[223][11]);
78 float k1 = (p2->y[223][11]);
79 // CHECK-NEXT: ((p2->y)[23])[1] = k1;
80 ((p2->y)[23])[1] = k1;
81 // CHECK-NEXT: ++(((p2->x)[23])[1]);
82 ++(((p2->x)[23])[1]);
83 // CHECK-NEXT: j1 = ((p2->x)[23])[1] = j1;
84 j1 = ((p2->x)[23])[1] = j1;
85 // CHECK-NEXT: return Test1::GetTest1()->X;
86 return Test1::GetTest1()->X;
88 #endif // HEADER