MATCH: Improve `A CMP 0 ? A : -A` set of patterns to use bitwise_equal_p.
[official-gcc.git] / gcc / testsuite / gdc.test / fail_compilation / noreturn2.d
blob66c1d5287f59960d0cc251e5ae0b405f78f4e3de
1 /*
2 REQUIRED_ARGS: -w -o-
4 TEST_OUTPUT:
5 ---
6 fail_compilation/noreturn2.d(18): Error: expected return type of `noreturn`, not `void`
7 ---
9 https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1034.md
12 alias noreturn = typeof(*null);
14 void doStuff();
16 noreturn returnVoid()
18 return doStuff();
23 TEST_OUTPUT:
24 ---
25 fail_compilation/noreturn2.d(37): Error: expected return type of `int`, not `string`:
26 fail_compilation/noreturn2.d(35): Return type of `int` inferred here.
27 ---
30 auto missmatch(int i)
32 if (i < 0)
33 return assert(false);
34 if (i == 0)
35 return i;
36 if (i > 0)
37 return "";
41 TEST_OUTPUT:
42 ---
43 fail_compilation/noreturn2.d(50): Error: function `noreturn2.returns` is typed as `NR` but does return
44 fail_compilation/noreturn2.d(50): `noreturn` functions must either throw, abort or loop indefinitely
45 ---
48 enum NR : noreturn;
50 NR returns()
52 // Fallthrough despite noreturn
56 TEST_OUTPUT:
57 ---
58 fail_compilation/noreturn2.d(64): Error: cannot implicitly convert expression `1` of type `int` to `noreturn`
59 ---
62 noreturn returnsValue()
64 return 1;
68 TEST_OUTPUT:
69 ---
70 fail_compilation/noreturn2.d(75): Error: expected return type of `int`, not `void`
71 ---
73 int returnVoid2()
75 return doStuff();
79 TEST_OUTPUT:
80 ---
81 fail_compilation/noreturn2.d(89): Error: mismatched function return type inference of `void` and `int`
82 ---
84 auto returnVoid3(int i)
86 if (i > 0)
87 return i;
88 else
89 return doStuff();
93 TEST_OUTPUT:
94 ---
95 fail_compilation/noreturn2.d(104): Error: `object.Exception` is thrown but not caught
96 fail_compilation/noreturn2.d(100): Error: function `noreturn2.doesNestedThrow` may throw but is marked as `nothrow`
97 ---
100 int doesNestedThrow(int i) nothrow
102 // Weird formatting is intended to check the loc
103 return i ? i++ :
104 throw
106 Exception("")
110 int doesNestedThrowThrowable(int i) nothrow
112 return i ? i++ : throw new Error("");
116 TEST_OUTPUT:
118 fail_compilation/noreturn2.d(130): Error: cannot create instance of interface `I`
119 fail_compilation/noreturn2.d(133): Error: can only throw class objects derived from `Throwable`, not type `int[]`
120 fail_compilation/noreturn2.d(138): Error: undefined identifier `UnkownException`
124 int throwInvalid(int i) nothrow
126 static interface I {}
127 // Weird formatting is intended to check the loc
128 return
129 throw
133 throw
135 int[4]
137 throw
139 UnkownException("")
144 https://issues.dlang.org/show_bug.cgi?id=24054
145 TEST_OUTPUT:
147 fail_compilation/noreturn2.d(153): Error: cannot return from `noreturn` function
148 fail_compilation/noreturn2.d(153): Consider adding an endless loop, `assert(0)`, or another `noreturn` expression
151 const(noreturn) f()
153 return;