2 // REQUIRED_ARGS: -d -preview=dip1000
4 extern(C) int printf(const char*, ...);
15 /********************************************/
25 printf("Foo.this()\n");
32 printf("Foo.~this()\n");
40 scope Foo f = new Foo();
56 /********************************************/
62 scope (exit) { printf("test1\n"); assert(x == 3); x = 4; }
63 scope (exit) { printf("test2\n"); assert(x == 2); x = 3; }
64 scope (exit) { printf("test3\n"); assert(x == 1); x = 2; }
65 printf("test4\n"); assert(x == 0); x = 1;
70 /********************************************/
76 scope (success) { printf("test1\n"); assert(x == 3); x = 4; }
77 scope (success) { printf("test2\n"); assert(x == 2); x = 3; }
78 scope (success) { printf("test3\n"); assert(x == 1); x = 2; }
79 printf("test4\n"); assert(x == 0); x = 1;
84 /********************************************/
91 scope (exit) { printf("test1\n"); assert(x == 3); x = 4; }
92 scope (exit) { printf("test2\n"); assert(x == 2); x = 3; }
95 scope (exit) { printf("test3\n"); assert(x == 1); x = 2; }
96 printf("test4\n"); assert(x == 0); x = 1;
104 /********************************************/
111 scope (success) { printf("test1\n"); assert(x == 3); x = 4; }
112 scope (success) { printf("test2\n"); assert(x == 2); x = 3; }
115 scope (success) { printf("test3\n"); assert(x == 1); x = 2; }
116 printf("test4\n"); assert(x == 0); x = 1;
124 /********************************************/
129 scope (failure) { assert(0); }
132 scope (failure) { printf("test1\n"); assert(x == 3); x = 4; }
133 scope (failure) { printf("test2\n"); assert(x == 2); x = 3; }
136 scope (failure) { printf("test3\n"); assert(x == 1); x = 2; }
137 printf("test4\n"); assert(x == 0); x = 1;
145 /********************************************/
153 scope (success) { assert(x == 1); x = 2; }
165 /********************************************/
183 /********************************************/
192 r9 ~= cast(char)(n + '0');
200 assert(r9 == "12345");
203 /********************************************/
207 T readMessageBegin() { return 3.0; }
209 T bar10() { return 8.0; }
212 // Send RPC request, etc.
214 scope (exit) readMessageEnd();
217 // Read message off the wire.
230 d = (((((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))+(((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d)))))/((((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))+(((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d)))))+((((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))+(((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d)))))/((((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))+(((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))))*(((((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))+(((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d)))))/((((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))+(((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d)))))+((((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))+(((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d)))))/((((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))+(((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))));
234 /********************************************/
238 debug printf("error\n");
240 printf("do something\n");
243 /********************************************/
245 char[] dup12()(char[] a) // although inferred pure, don't infer a is 'return'
259 /********************************************/
261 void test7049() @safe
266 scope (failure) { count++; }
267 scope (failure) { count++; }
268 throw new Exception("failed");
273 } catch(Exception e) {
278 /********************************************/
280 // https://issues.dlang.org/show_bug.cgi?id=16747
282 void test16747() @safe
284 scope o = new Object();
287 /********************************************/
289 void bar11(int*, int*) { }
298 /********************************************/
299 // https://issues.dlang.org/show_bug.cgi?id=17432
301 int test17432(scope int delegate() dg)
306 // stripped down version of std.traits.Parameters
307 template Parameters(alias func)
309 static if (is(typeof(func) P == function))
310 alias Parameters = P;
312 static assert(0, "unsupported");
315 alias op = Parameters!(test17432)[0];
316 enum typeString = op.stringof;
317 static assert(typeString == "int delegate()"); // no scope added?
318 mixin(typeString ~ " dg;");
319 alias ty = typeof(dg);
321 static assert(op.stringof == ty.stringof);
322 static assert(op.mangleof == ty.mangleof);
324 void test17432_2()(scope void delegate () dg) { dg(); }
326 static assert(typeof(&test17432_2!()).stringof == "void function(scope void delegate() dg) @system");
328 /********************************************/
330 byte typify13(T)(byte val) { return val; }
331 alias INT8_C13 = typify13!byte;
333 /********************************************/
340 test14!(char[] function(return char[])) x14;
342 /********************************************/
343 // https://issues.dlang.org/show_bug.cgi?id=17935
357 ~this() @safe @nogc scope
361 @safe @nogc void test17395()
364 auto chunks = ByChunk!IO(buf[], IO());
365 chunks.__xdtor(); // auto-generated inclusive (fields and struct) dtor
368 /********************************************/
369 // https://issues.dlang.org/show_bug.cgi?id=20569
371 void test20569() @safe
379 /* explicit `scope`: */
381 scope int* p1 = &s1.value;
383 /* inferred `scope`: */
389 /********************************************/