| 1 |
/** |
| 2 |
REQUIRED_ARGS: -preview=systemVariables |
| 3 |
TEST_OUTPUT: |
| 4 |
--- |
| 5 |
fail_compilation/systemvariables_void_init.d(48): Error: `void` initializing a type with unsafe bit patterns is not allowed in a `@safe` function |
| 6 |
fail_compilation/systemvariables_void_init.d(49): Error: `void` initializing a type with unsafe bit patterns is not allowed in a `@safe` function |
| 7 |
fail_compilation/systemvariables_void_init.d(50): Error: `void` initializing a type with unsafe bit patterns is not allowed in a `@safe` function |
| 8 |
fail_compilation/systemvariables_void_init.d(51): Error: void intializing a bool (which must always be 0 or 1) is not allowed in a `@safe` function |
| 9 |
fail_compilation/systemvariables_void_init.d(52): Error: void intializing a bool (which must always be 0 or 1) is not allowed in a `@safe` function |
| 10 |
fail_compilation/systemvariables_void_init.d(53): Error: `void` initializing a type with unsafe bit patterns is not allowed in a `@safe` function |
| 11 |
fail_compilation/systemvariables_void_init.d(54): Error: `void` initializing a type with unsafe bit patterns is not allowed in a `@safe` function |
| 12 |
--- |
| 13 |
*/ |
| 14 |
|
| 15 |
struct S |
| 16 |
{ |
| 17 |
int x; |
| 18 |
@system int y; |
| 19 |
} |
| 20 |
|
| 21 |
struct C |
| 22 |
{ |
| 23 |
S[2] x; |
| 24 |
} |
| 25 |
|
| 26 |
enum E : C |
| 27 |
{ |
| 28 |
x = C.init, |
| 29 |
} |
| 30 |
|
| 31 |
enum B : bool |
| 32 |
{ |
| 33 |
x, |
| 34 |
} |
| 35 |
|
| 36 |
struct SB |
| 37 |
{ |
| 38 |
bool x; |
| 39 |
} |
| 40 |
|
| 41 |
struct SSB |
| 42 |
{ |
| 43 |
SB sb; |
| 44 |
} |
| 45 |
|
| 46 |
void main() @safe |
| 47 |
{ |
| 48 |
S s = void; |
| 49 |
C c = void; |
| 50 |
E e = void; |
| 51 |
const bool b = void; |
| 52 |
B bb = void; |
| 53 |
SB sb = void; |
| 54 |
SSB ssb = void; |
| 55 |
} |
| 56 |
|
| 57 |
// The following test is reduced from Phobos. The compiler generates this `opAssign`: |
| 58 |
// (CopyPreventer __swap2 = void;) , __swap2 = this , (this = p , __swap2.~this()); |
| 59 |
// The compiler would give an error about void initialization a struct with a bool, |
| 60 |
// but it can be trusted in this case because it's a compiler generated temporary. |
| 61 |
auto staticArray(T)(T a) @safe |
| 62 |
{ |
| 63 |
T c; |
| 64 |
c = a; |
| 65 |
} |
| 66 |
|
| 67 |
void assignmentTest() @safe |
| 68 |
{ |
| 69 |
static struct CopyPreventer |
| 70 |
{ |
| 71 |
bool on; |
| 72 |
this(this) @safe {} |
| 73 |
~this() { } |
| 74 |
} |
| 75 |
|
| 76 |
staticArray(CopyPreventer()); |
| 77 |
} |