Debian Codegraph @

gcc/testsuite/gdc.test/runnable/test17258.d

raw
1 class ByNameC(alias Var)
2 {
3 alias var = Var;
4 }
5
6 struct ByNameS(alias Var)
7 {
8 alias var = Var;
9 ubyte value = 1;
10 }
11
12 void main()
13 {
14 ulong x;
15 ByNameS!x v;
16 ubyte w = 2;
17
18 v.var = 0xAA_BB; /* stomps over v.value and w */
19
20 assert(w == 2);
21 assert(v.value == 1);
22 //printf("%x\n", w); /* prints "aa", should be 2 */
23 //printf("%x\n", v.value); /* prints "bb", should be 1 */
24
25 auto c = new ByNameC!x;
26 c.var = 0xAA_BB; /* stomps over c.__vptr */
27
28 assert(*cast(ulong*)c != 0xAA_BB);
29 //printf("%x\n", *cast(ulong*)c); /* prints "aabb", should be pointer value */
30
31 assert(x == 0xAA_BB);
32 //printf("%lx\n", x); /* prints 0, should be "aabb" */
33 }