MATCH: Improve `A CMP 0 ? A : -A` set of patterns to use bitwise_equal_p.
[official-gcc.git] / gcc / testsuite / gdc.test / fail_compilation / noreturn.d
blob087b9e7c6466374dadb3941afacdd5bd4c3ac4d2
1 /*
2 REQUIRED_ARGS: -w -o-
4 TEST_OUTPUT:
5 ---
6 fail_compilation\noreturn.d(38): Error: Accessed expression of type `noreturn`
7 fail_compilation\noreturn.d(42): called from here: `assign()`
8 fail_compilation\noreturn.d(49): Error: Accessed expression of type `noreturn`
9 fail_compilation\noreturn.d(49): called from here: `foo(n)`
10 fail_compilation\noreturn.d(53): called from here: `calling()`
11 fail_compilation\noreturn.d(59): Error: Accessed expression of type `noreturn`
12 fail_compilation\noreturn.d(62): called from here: `nested()`
13 fail_compilation\noreturn.d(68): Error: Accessed expression of type `noreturn`
14 fail_compilation\noreturn.d(78): called from here: `casting(0)`
15 fail_compilation\noreturn.d(69): Error: Accessed expression of type `noreturn`
16 fail_compilation\noreturn.d(79): called from here: `casting(1)`
17 fail_compilation\noreturn.d(72): Error: Accessed expression of type `noreturn`
18 fail_compilation\noreturn.d(80): called from here: `casting(2)`
19 fail_compilation/noreturn.d(120): Error: uncaught CTFE exception `object.Exception("")`
20 ---
21 https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1034.md
24 alias noreturn = typeof(*null);
26 int pass()
28 noreturn n;
29 noreturn m;
30 return 0;
33 enum forcePass = pass();
35 int assign()
37 noreturn n;
38 noreturn m = n;
39 return 0;
42 enum forceAss = assign();
44 void foo(const noreturn) {}
46 int calling()
48 noreturn n;
49 foo(n);
50 return 0;
53 enum forceCall = calling();
55 int nested()
57 int[4] arr;
58 noreturn n;
59 return arr[n ? n : n];
62 enum forceNested = nested();
64 noreturn casting(int i)
66 final switch (i)
68 case 0: return cast(noreturn) i;
69 case 1: return cast(typeof(assert(0))) cast(double) i;
70 case 2, 3: {
71 noreturn n;
72 return cast() n;
75 assert(false);
78 enum forceCasting0 = casting(0);
79 enum forceCasting1 = casting(1);
80 enum forceCasting2 = casting(2);
83 struct HasNoreturnStruct
85 noreturn n;
88 int inStruct()
90 HasNoreturnStruct hn;
91 return hn.n;
94 enum forceInStruct = inStruct();
96 class HasNoreturnClass
98 noreturn n;
101 int inClass()
103 HasNoreturnClass hn = new HasNoreturnClass();
104 return hn.n;
107 enum forceInClass = inClass();
109 int inClassRef()
111 static void byRef(ref noreturn n) {}
112 HasNoreturnClass hn = new HasNoreturnClass();
113 byRef(hn.n);
114 return 0;
117 enum forceInClassRef = inClassRef();
120 enum throwEnum = throw new Exception("");
124 https://issues.dlang.org/show_bug.cgi?id=23063
126 TEST_OUTPUT:
128 fail_compilation/noreturn.d(135): Error: Accessed expression of type `noreturn`
129 fail_compilation/noreturn.d(138): called from here: `func()`
132 noreturn func()
134 noreturn a;
135 return a;
138 enum f = func();