Debian Codegraph @

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

raw
1 // DFLAGS:
2 // REQUIRED_ARGS: -defaultlib=
3 // EXTRA_SOURCES: extra-files/minimal/object.d
4
5 // This test ensures that interfaces and classes can be used in a minimal
6 // runtime as long as they only contain shared static members. Non-shared
7 // static members would require a thread-local storage (TLS) implementation.
8
9 interface I
10 {
11 shared static int i;
12 }
13
14 class A : I
15 {
16 shared static int a;
17 }
18
19 class B : A
20 {
21 shared static int b;
22
23 static int sumAll()
24 {
25 return b + a + i;
26 }
27 }
28
29 void poorMansAssert(bool condition)
30 {
31 if (!condition)
32 {
33 static char* hlt;
34 *hlt = 0;
35 }
36 }
37
38 void main()
39 {
40 B.i = 32;
41 B.a = 42;
42 B.b = 52;
43
44 poorMansAssert(B.i == 32 || B.a == 42 || B.b == 52);
45 poorMansAssert(B.sumAll() == (32 + 42 + 52));
46 }