Skip to content

Commit f02b9d6

Browse files
ntrelthewilsonator
authored andcommitted
Fix #21562 - Trying to fill a void[] causes dmd to segfault
1 parent c6fca39 commit f02b9d6

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

compiler/src/dmd/expressionsem.d

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11635,7 +11635,14 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
1163511635
t1.isStaticOrDynamicArray() &&
1163611636
t1.nextOf().toBasetype().ty == Tvoid)
1163711637
{
11638-
if (t2.nextOf().implicitConvTo(t1.nextOf()))
11638+
auto t2n = t2.nextOf();
11639+
if (!t2n)
11640+
{
11641+
// filling not allowed
11642+
error(exp.loc, "cannot copy `%s` to `%s`",
11643+
t2.toChars(), t1.toChars());
11644+
}
11645+
else if (t2n.implicitConvTo(t1.nextOf()))
1163911646
{
1164011647
if (sc.setUnsafe(false, exp.loc, "copying `%s` to `%s`", t2, t1))
1164111648
return setError();

compiler/test/fail_compilation/test15704.d

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/*
22
* TEST_OUTPUT:
33
---
4-
fail_compilation/test15704.d(17): Error: copying `void[]` to `void[]` is not allowed in a `@safe` function
5-
fail_compilation/test15704.d(18): Error: copying `const(void)[]` to `void[]` is not allowed in a `@safe` function
6-
fail_compilation/test15704.d(19): Deprecation: copying `int[]` to `void[]` will become `@system` in a future release
4+
fail_compilation/test15704.d(19): Error: copying `void[]` to `void[]` is not allowed in a `@safe` function
5+
fail_compilation/test15704.d(20): Error: copying `const(void)[]` to `void[]` is not allowed in a `@safe` function
6+
fail_compilation/test15704.d(21): Deprecation: copying `int[]` to `void[]` will become `@system` in a future release
7+
fail_compilation/test15704.d(22): Error: cannot implicitly convert expression `cast(byte)0` of type `byte` to `void[]`
8+
fail_compilation/test15704.d(22): Error: cannot copy `byte` to `void[]`
79
---
810
*/
911

@@ -17,4 +19,5 @@ void main() @safe {
1719
arr1[] = arr2[]; // overwrites pointers with arbitrary ints
1820
arr1[] = new const(void)[3];
1921
arr1[] = [5];
22+
arr1[] = byte(); // filling not allowed
2023
}

0 commit comments

Comments
 (0)