d: Merge upstream dmd 568496d5b, druntime 178c44ff, phobos 574bf883b.
[official-gcc.git] / gcc / testsuite / gdc.test / compilable / noreturn1.d
blobb041e072e9c2cb0833f904423768ec00a4fb5410
1 /*
2 REQUIRED_ARGS: -w
3 TEST_OUTPUT:
4 ---
5 noreturn
6 ---
8 Basic properties and usage mentioned in the DIP:
9 https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1034.md
12 alias noreturn = typeof(*null);
13 pragma(msg, noreturn);
15 static assert(!is(noreturn == void));
17 // Fails
18 // static assert(is( typeof([]) == noreturn[] ));
19 // static assert(is( typeof([][0]) == noreturn ));
21 static assert(is( typeof(assert(0)) == noreturn ));
23 // Does not parse yet
24 // static assert(is( typeof(throw new Exception()) == noreturn ));
26 static assert(is(noreturn == noreturn));
27 static assert(!is(noreturn == const noreturn));
28 static assert(is(noreturn : const noreturn));
30 static assert(!is(noreturn == int));
31 static assert(is(noreturn : int));
33 // Covariance
34 static assert(is(noreturn[] : int[]));
35 static assert(is(noreturn* : int*));
36 static assert(is(noreturn function() : int function()));
37 static assert(is(noreturn delegate() : int delegate()));
39 // Reject inverse conversions
40 static assert(!is(int[] : noreturn[]));
41 static assert(!is(int* : noreturn*));
42 static assert(!is(int function() : noreturn function()));
43 static assert(!is(int delegate() : noreturn delegate()));
45 static assert(noreturn.mangleof == "Nn"); // Changed from b due to conflicts with bool
46 static assert(noreturn.sizeof == 0);
47 static assert(noreturn.alignof == 0);
49 static assert((noreturn*).sizeof == (int*).sizeof);
50 static assert((noreturn[]).sizeof == (int[]).sizeof);
52 static assert(is(typeof(noreturn.init) == noreturn));
53 static assert(is(typeof((const noreturn).init) == const noreturn));
54 static assert(is(typeof((immutable noreturn).init) == immutable noreturn));
55 static assert(is(typeof((shared noreturn).init) == shared noreturn));
57 version (DigitalMars)
58 noreturn exits(int* p)
60 *p = 3;
61 assert(false); // *p could be valid
64 noreturn exit();
66 noreturn pureexits() @nogc nothrow pure @safe { assert(0); }
68 noreturn callpureexits() { pureexits(); }
70 noreturn returnExits()
72 return pureexits();
75 void alsoExits()
77 return assert(0);
80 int thisAlsoExits()
82 return assert(0);
85 void cast_()
87 noreturn n;
88 int i = n;
91 int test1(int i)
93 if (exit())
94 return i + 1;
95 return i - 1;
98 noreturn tlsNoreturn;
99 __gshared noreturn globalNoreturn;
101 template CreateTLS(A)
103 A a;
106 void* useTls()
108 alias Tnr = CreateTLS!noreturn;
109 void* a1 = &Tnr.a;
110 void* a2 = &tlsNoreturn;
111 void* a3 = &globalNoreturn;
112 return a1 < a2 ? a2 : a3;