]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gdc.test/compilable/noreturn1.d
d: Import dmd b8384668f, druntime e6caaab9, phobos 5ab9ad256 (v2.098.0-beta.1)
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / compilable / noreturn1.d
CommitLineData
5a0aa603 1/*
5fee5ec3 2REQUIRED_ARGS: -w
5a0aa603
IB
3TEST_OUTPUT:
4---
5noreturn
6---
5fee5ec3
IB
7
8Basic properties and usage mentioned in the DIP:
9https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1034.md
5a0aa603
IB
10*/
11
12alias noreturn = typeof(*null);
13pragma(msg, noreturn);
14
5fee5ec3
IB
15static assert(!is(noreturn == void));
16
17// Fails
18// static assert(is( typeof([]) == noreturn[] ));
19// static assert(is( typeof([][0]) == noreturn ));
20
21static assert(is( typeof(assert(0)) == noreturn ));
22
23// Does not parse yet
24// static assert(is( typeof(throw new Exception()) == noreturn ));
25
26static assert(is(noreturn == noreturn));
27static assert(!is(noreturn == const noreturn));
28static assert(is(noreturn : const noreturn));
29
30static assert(!is(noreturn == int));
31static assert(is(noreturn : int));
32
33// Covariance
34static assert(is(noreturn[] : int[]));
35static assert(is(noreturn* : int*));
36static assert(is(noreturn function() : int function()));
37static assert(is(noreturn delegate() : int delegate()));
38
39// Reject inverse conversions
40static assert(!is(int[] : noreturn[]));
41static assert(!is(int* : noreturn*));
42static assert(!is(int function() : noreturn function()));
43static assert(!is(int delegate() : noreturn delegate()));
44
45static assert(noreturn.mangleof == "Nn"); // Changed from b due to conflicts with bool
46static assert(noreturn.sizeof == 0);
47static assert(noreturn.alignof == 0);
48
49static assert((noreturn*).sizeof == (int*).sizeof);
50static assert((noreturn[]).sizeof == (int[]).sizeof);
51
52version (DigitalMars)
53 noreturn exits(int* p) { *p = 3; }
5a0aa603
IB
54
55noreturn exit();
56
5fee5ec3
IB
57noreturn pureexits() @nogc nothrow pure @safe { assert(0); }
58
59noreturn callpureexits() { pureexits(); }
60
5a0aa603
IB
61int test1(int i)
62{
63 if (exit())
64 return i + 1;
65 return i - 1;
66}