Debian Codegraph @

gcc/testsuite/gdc.dg/torture/pr96153.d

raw
1 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96153
2 // { dg-additional-options "-fmain -funittest" }
3 // { dg-do run }
4 // { dg-skip-if "needs gcc/config.d" { ! d_runtime } }
5 struct Checked(T, Hook)
6 {
7 private T payload;
8 Hook hook;
9
10 size_t toHash() const nothrow @safe
11 {
12 return hashOf(payload) ^ hashOf(hook);
13 }
14 }
15
16 Checked!(T, Hook) checked(Hook, T)(const T value)
17 {
18 return Checked!(T, Hook)(value);
19 }
20
21 @system unittest
22 {
23 static struct Hook1
24 {
25 uint var1 = uint.max;
26 uint var2 = uint.max;
27 }
28
29 assert(checked!Hook1(12).toHash() != checked!Hook1(13).toHash());
30 assert(checked!Hook1(13).toHash() == checked!Hook1(13).toHash());
31
32 static struct Hook2
33 {
34 uint var1 = uint.max;
35 ushort var2 = ushort.max;
36 }
37
38 assert(checked!Hook2(12).toHash() != checked!Hook2(13).toHash());
39 assert(checked!Hook2(13).toHash() == checked!Hook2(13).toHash());
40
41 static struct Hook3
42 {
43 ulong var1 = ulong.max;
44 uint var2 = uint.max;
45 }
46
47 assert(checked!Hook3(12).toHash() != checked!Hook3(13).toHash());
48 assert(checked!Hook3(13).toHash() == checked!Hook3(13).toHash());
49 }