blob: a3a348dd0338e921c72f4b634b1c4ec3801209b3 [file] [log] [blame]
/* TEST_OUTPUT:
---
fail_compilation/test21665.d(18): Error: variable `test21665.test1.s` `void` initializers for structs with invariants are not allowed in safe functions
fail_compilation/test21665.d(30): Error: field `U.s` cannot access structs with invariants in `@safe` code that overlap other fields
---
*/
// https://issues.dlang.org/show_bug.cgi?id=21665
struct ShortString {
private ubyte length;
private char[15] data;
invariant { assert(length <= data.length); }
}
@safe void test1() {
ShortString s = void;
}
union U
{
int n;
ShortString s;
}
@safe void test2()
{
U u;
u.s.length = 3;
}