Skip to content

Commit 5807d3a

Browse files
authored
[spec/arrays] Copying into void array is not @safe (#4262)
1 parent 289f9f3 commit 5807d3a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

spec/arrays.dd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,11 @@ $(H3 $(LNAME2 void_arrays, Void Arrays))
14151415
elements in its original type. Array indices in slicing
14161416
operations are interpreted as byte indices. A void array cannot be indexed.)
14171417

1418+
$(P Another array can be $(RELATIVE_LINK2 array-copying, copied) into a void array's elements, but not in a
1419+
$(DDSUBLINK spec/function, safe-functions, `@safe` function).
1420+
This is because the void array may hold pointers.
1421+
A void array cannot be $(RELATIVE_LINK2 array-setting, filled).)
1422+
14181423
$(P Arrays of any type can be implicitly converted to a (tail qualified) void array - the
14191424
compiler inserts the appropriate calculations so that the $(D .length) of
14201425
the resulting array's size is in bytes rather than number of elements. Void

spec/function.dd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3857,6 +3857,7 @@ $(H3 $(LNAME2 safe-functions, Safe Functions))
38573857
$(LI No $(DDSUBLINK spec/expression, pointer_arithmetic, pointer arithmetic)
38583858
(including pointer indexing & slicing).)
38593859
$(LI Cannot access array $(DDSUBLINK spec/arrays, ptr-property, `.ptr` property).)
3860+
$(LI Cannot copy into a $(DDSUBLINK spec/arrays, void_arrays, void array).)
38603861
$(LI Cannot access union fields that:)
38613862
* Have pointers or references overlapping with other types
38623863
* Have invariants overlapping with other types

0 commit comments

Comments
 (0)