d: Merge upstream dmd, druntime 4ca4140e58, phobos 454dff14d.
[official-gcc.git] / gcc / testsuite / gdc.test / runnable / test17684.d
blobe10265558e8498afce19511b5f1c3376609678ed
1 /*
2 TEST_OUTPUT:
3 ---
4 runnable/test17684.d(37): Deprecation: alias this for classes/interfaces is deprecated
5 runnable/test17684.d(54): Deprecation: alias this for classes/interfaces is deprecated
6 runnable/test17684.d(54): Deprecation: alias this for classes/interfaces is deprecated
7 runnable/test17684.d(37): Deprecation: alias this for classes/interfaces is deprecated
8 ---
9 */
11 struct StructField(T)
13 static T Field;
14 static alias Field this;
17 struct StructProperty(T)
19 static T Field;
21 static @property T property()
23 return Field;
26 static @property void property(T value)
28 Field = value;
31 static alias property this;
34 class ClassField(T)
36 static T Field;
37 static alias Field this;
40 class ClassProperty(T)
42 static T Field;
44 static @property T property()
46 return Field;
49 static @property void property(T value)
51 Field = value;
54 static alias property this;
57 bool boolTest(T)()
59 alias t = T;
61 t = false; // tests AssignExp
62 assert(t == false);
64 bool boolValue = t; // tests AssignExp
65 assert(boolValue == false);
67 t = !t; // tests NotExp
68 assert(t == true);
70 boolValue = t;
71 assert(boolValue == true);
73 assert(boolValue && t); // tests AndAndExp
74 assert(t && boolValue);
76 boolValue = false;
77 assert(boolValue || t); // tests OrOrExp
78 assert(t || boolValue);
80 assert(t != boolValue); // tests CmpExp
81 assert(boolValue != t);
83 boolValue = true;
84 assert(t == boolValue);
85 assert(boolValue == t);
87 t = true; // tests inferType
88 auto inferredValue = t;
89 assert(inferredValue == true);
91 t = true; // tests function argument
92 bool functionCall(bool test)
94 return test;
96 assert(t == functionCall(t));
98 t = true; // tests CastExp
99 assert(t == cast(bool)t);
101 t = true;
102 return t; // tests ReturnStatement
105 int intTest(T)()
107 alias t = T;
109 t = 42; // tests AssignExp
110 assert(t == 42);
112 int intValue = t;
113 assert(intValue == 42);
115 assert(t == 42); // tests CmpExp
116 assert(42 == t);
117 assert(t != 43);
118 assert(43 != t);
119 assert(t < 43);
120 assert(43 > t);
121 assert(t <= 42);
122 assert(42 >= t);
124 t = 42; // tests CastExp
125 assert(42 == cast(int)t);
127 // These currently don't work for properties due to https://issues.dlang.org/show_bug.cgi?id=8006
128 static if (!(typeid(T) is typeid(StructProperty!int)) && !(typeid(T) is typeid(ClassProperty!int)))
130 t++; // test a few unary and binary operators
131 assert(t == 43);
133 t += 1;
134 assert(t == 44);
136 t--;
137 assert(t == 43);
139 t -= 1;
140 assert(t == 42);
143 assert(~t == ~42); // tests ComExp
145 return t; // tests ReturnStatement
148 void main()
150 assert(boolTest!(StructField!(bool))());
151 assert(boolTest!(StructProperty!(bool))());
152 assert(boolTest!(ClassField!(bool))());
153 assert(boolTest!(ClassProperty!(bool))());
155 assert(intTest!(StructField!(int))() == 42);
156 assert(intTest!(StructProperty!(int))() == 42);
157 assert(intTest!(ClassField!(int))() == 42);
158 assert(intTest!(ClassProperty!(int))() == 42);