Debian Codegraph @

gcc/testsuite/gdc.test/fail_compilation/noreturn.d

raw
1 /*
2 REQUIRED_ARGS: -w -o-
3
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
22 */
23
24 alias noreturn = typeof(*null);
25
26 int pass()
27 {
28 noreturn n;
29 noreturn m;
30 return 0;
31 }
32
33 enum forcePass = pass();
34
35 int assign()
36 {
37 noreturn n;
38 noreturn m = n;
39 return 0;
40 }
41
42 enum forceAss = assign();
43
44 void foo(const noreturn) {}
45
46 int calling()
47 {
48 noreturn n;
49 foo(n);
50 return 0;
51 }
52
53 enum forceCall = calling();
54
55 int nested()
56 {
57 int[4] arr;
58 noreturn n;
59 return arr[n ? n : n];
60 }
61
62 enum forceNested = nested();
63
64 noreturn casting(int i)
65 {
66 final switch (i)
67 {
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;
73 }
74 }
75 assert(false);
76 }
77
78 enum forceCasting0 = casting(0);
79 enum forceCasting1 = casting(1);
80 enum forceCasting2 = casting(2);
81
82 /*
83 struct HasNoreturnStruct
84 {
85 noreturn n;
86 }
87
88 int inStruct()
89 {
90 HasNoreturnStruct hn;
91 return hn.n;
92 }
93
94 enum forceInStruct = inStruct();
95
96 class HasNoreturnClass
97 {
98 noreturn n;
99 }
100
101 int inClass()
102 {
103 HasNoreturnClass hn = new HasNoreturnClass();
104 return hn.n;
105 }
106
107 enum forceInClass = inClass();
108
109 int inClassRef()
110 {
111 static void byRef(ref noreturn n) {}
112 HasNoreturnClass hn = new HasNoreturnClass();
113 byRef(hn.n);
114 return 0;
115 }
116
117 enum forceInClassRef = inClassRef();
118 */
119
120 enum throwEnum = throw new Exception("");
121
122
123 /*
124 https://issues.dlang.org/show_bug.cgi?id=23063
125
126 TEST_OUTPUT:
127 ---
128 fail_compilation/noreturn.d(135): Error: Accessed expression of type `noreturn`
129 fail_compilation/noreturn.d(138): called from here: `func()`
130 ---
131 */
132 noreturn func()
133 {
134 noreturn a;
135 return a;
136 }
137
138 enum f = func();