dmd/compiler/test/fail_compilation/test21665.d
Dennis 9b94878c85
Make safe error messages consistent (#20654)
Co-authored-by: Dennis Korpel <dennis@sarc.nl>
2025-01-08 13:46:38 +08:00

31 lines
612 B
D

/* TEST_OUTPUT:
---
fail_compilation/test21665.d(18): Error: `void` initializing a struct with an invariant is not allowed in a `@safe` function
fail_compilation/test21665.d(30): Error: accessing overlapped field `U.s` with a structs invariant is not allowed in a `@safe` function
---
*/
// 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;
}