Debian Codegraph @

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

raw
1 /*
2 TEST_OUTPUT:
3 ---
4 fail_compilation/var_func_attr.d(19): Error: cannot implicitly convert expression `() { static int g; g++; }` of type `void function() nothrow @nogc @safe` to `void function() pure`
5 ---
6 */
7
8 // Test the effect of function attributes on variables
9 // See:
10 // https://issues.dlang.org/show_bug.cgi?id=7432
11 // https://github.com/dlang/dmd/pull/14199
12 // Usually it's a no-op, but the attribute can apply to the function/delegate type of the variable
13 // The current behavior is weird, so this is a test of the current behavior, not necessarily the desired behavior
14
15 // No-op
16 pure int x;
17
18 // Applies to function type (existing code in dmd and Phobos relies on this)
19 pure void function() pf = () {
20 static int g;
21 g++;
22 };
23
24 // Function attributes currently don't apply to inferred types (somewhat surprisingly)
25 nothrow nf = () {
26 throw new Exception("");
27 };
28
29 // Neither do they apply to indirections
30 alias F = void function();
31
32 pure F pf2 = () {
33 static int g;
34 g++;
35 };