Fix 20148 - void initializated bool can be both true and false

This commit is contained in:
Dennis Korpel 2023-06-28 12:12:25 +02:00 committed by The Dlang Bot
parent 8272384b3e
commit 0b677d90ee
6 changed files with 86 additions and 26 deletions

View file

@ -2,9 +2,13 @@
REQUIRED_ARGS: -preview=systemVariables
TEST_OUTPUT:
---
fail_compilation/systemvariables_void_init.d(29): Error: `void` initializers for `@system` variables not allowed in safe functions
fail_compilation/systemvariables_void_init.d(30): Error: `void` initializers for `@system` variables not allowed in safe functions
fail_compilation/systemvariables_void_init.d(31): Error: `void` initializers for `@system` variables not allowed in safe functions
fail_compilation/systemvariables_void_init.d(48): Error: `void` initializers for types with unsafe bit patterns are not allowed in safe functions
fail_compilation/systemvariables_void_init.d(49): Error: `void` initializers for types with unsafe bit patterns are not allowed in safe functions
fail_compilation/systemvariables_void_init.d(50): Error: `void` initializers for types with unsafe bit patterns are not allowed in safe functions
fail_compilation/systemvariables_void_init.d(51): Error: a `bool` must be 0 or 1, so void intializing it is not allowed in safe functions
fail_compilation/systemvariables_void_init.d(52): Error: a `bool` must be 0 or 1, so void intializing it is not allowed in safe functions
fail_compilation/systemvariables_void_init.d(53): Error: `void` initializers for types with unsafe bit patterns are not allowed in safe functions
fail_compilation/systemvariables_void_init.d(54): Error: `void` initializers for types with unsafe bit patterns are not allowed in safe functions
---
*/
@ -24,9 +28,50 @@ enum E : C
x = C.init,
}
enum B : bool
{
x,
}
struct SB
{
bool x;
}
struct SSB
{
SB sb;
}
void main() @safe
{
S s = void;
C c = void;
E e = void;
const bool b = void;
B bb = void;
SB sb = void;
SSB ssb = void;
}
// The following test is reduced from Phobos. The compiler generates this `opAssign`:
// (CopyPreventer __swap2 = void;) , __swap2 = this , (this = p , __swap2.~this());
// The compiler would give an error about void initialization a struct with a bool,
// but it can be trusted in this case because it's a compiler generated temporary.
auto staticArray(T)(T a) @safe
{
T c;
c = a;
}
void assignmentTest() @safe
{
static struct CopyPreventer
{
bool on;
this(this) @safe {}
~this() { }
}
staticArray(CopyPreventer());
}