125 lines · cpp
1// RUN: %clang_cc1 -ast-print -verify -triple=x86_64-pc-win32 -fms-compatibility %s -o - | FileCheck %s2// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fms-compatibility -emit-pch -o %t -verify %s3// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fms-compatibility -include-pch %t %s -ast-print -o - | FileCheck %s4// RUN: %clang_cc1 -fdeclspec -fsyntax-only -verify %s -std=c++235// expected-no-diagnostics6 7#ifndef HEADER8#define HEADER9 10class Test1 {11private:12 int x_;13 14public:15 Test1(int x) : x_(x) {}16 __declspec(property(get = get_x)) int X;17 int get_x() const { return x_; }18 static Test1 *GetTest1() { return new Test1(10); }19};20 21class S {22public:23 __declspec(property(get=GetX,put=PutX)) int x[];24 int GetX(int i, int j) { return i+j; }25 void PutX(int i, int j, int k) { j = i = k; }26 __declspec(property(get=GetY,put=PutY)) int y[][];27 int GetY(int i, int j) { return i+j; }28 void PutY(int i, int j, int k) { j = i = k; }29 __declspec(property(get=GetZ,put=PutZ)) int z[][][];30 int GetZ(int i, int j, int k);31 void PutZ(int i, int j, int k, int val);32};33 34template <typename T>35class St {36public:37 __declspec(property(get=GetX,put=PutX)) T x[];38 T GetX(T i, T j) { return i+j; }39 T PutX(T i, T j, T k) { return j = i = k; }40 __declspec(property(get=GetY,put=PutY)) T y[][];41 T GetY(T i, T j) { return i+j; }42 T PutY(T i, T j, T k) { return j = i = k; }43 __declspec(property(get=GetZ,put=PutZ)) T z[][][];44 T GetZ(T i, T j, T k) { return i+j+k; }45 T PutZ(T i, T j, T k, T v) { return j = i = k = v; }46 ~St() { x[0][0] = x[1][1]; y[0][0] = x[1][1]; z[0][1][2] = z[2][1][0]; }47};48 49// CHECK: this->x[0][0] = this->x[1][1];50// CHECK: this->y[0][0] = this->x[1][1];51// CHECK: this->z[0][1][2] = this->z[2][1][0];52// CHECK: this->x[0][0] = this->x[1][1];53// CHECK: this->y[0][0] = this->x[1][1];54// CHECK: this->z[0][1][2] = this->z[2][1][0];55 56// CHECK-LABEL: main57int main(int argc, char **argv) {58 S *p1 = 0;59 St<float> *p2 = 0;60 // CHECK: St<int> a;61 St<int> a;62 // CHECK-NEXT: int j = (p1->x)[223][11];63 int j = (p1->x)[223][11];64 // CHECK-NEXT: (p1->x[23])[1] = j;65 (p1->x[23])[1] = j;66 // CHECK-NEXT: int k = (p1->y)[223][11];67 int k = (p1->y)[223][11];68 // CHECK-NEXT: (p1->y[23])[1] = k;69 (p1->y[23])[1] = k;70 // CHECK-NEXT: int k3 = p1->z[1][2][3];71 int k3 = p1->z[1][2][3];72 // CHECK-NEXT: p1->z[0][2][1] = k3;73 p1->z[0][2][1] = k3;74 // CHECK-NEXT: float j1 = (p2->x[223][11]);75 float j1 = (p2->x[223][11]);76 // CHECK-NEXT: ((p2->x)[23])[1] = j1;77 ((p2->x)[23])[1] = j1;78 // CHECK-NEXT: float k1 = (p2->y[223][11]);79 float k1 = (p2->y[223][11]);80 // CHECK-NEXT: ((p2->y)[23])[1] = k1;81 ((p2->y)[23])[1] = k1;82 // CHECK-NEXT: ++(((p2->x)[23])[1]);83 ++(((p2->x)[23])[1]);84 // CHECK-NEXT: j1 = ((p2->x)[23])[1] = j1;85 j1 = ((p2->x)[23])[1] = j1;86 // CHECK-NEXT: return Test1::GetTest1()->X;87 return Test1::GetTest1()->X;88}89 90struct X {91 int implicit_object_member_function() { return 0; }92 static int static_member_function() { return 0; }93 94 __declspec(property(get=implicit_object_member_function)) int imp;95 __declspec(property(get=static_member_function)) int st;96 97#if __cplusplus >= 202302L98 int explicit_object_member_function(this X self) { return 0; }99 __declspec(property(get=explicit_object_member_function)) int exp;100#endif101};102 103[[nodiscard]] X get_x();104void f() {105 (void) get_x().imp;106 (void) get_x().st;107#if __cplusplus >= 202302L108 (void) get_x().exp;109#endif110}111 112#if __cplusplus >= 202302L113struct Y {114 Y() = default;115 Y(const Y&) = delete;116 int explicit_object_member_function(this Y) { return 0; }117 __declspec(property(get = explicit_object_member_function)) int prop;118};119void g() {120 (void) Y().prop;121}122#endif123 124#endif // HEADER125