Skip to content

Commit c76a20f

Browse files
authored
Merge pull request #467 from mattheww/2024-10_zst_nullptr
Say that dereferencing a pointer to a ZST is no longer undefined
2 parents 0c10c30 + db1fac7 commit c76a20f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/exotic-sizes.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ consequence of types with no size. In particular, pointer offsets are no-ops,
106106
and allocators typically [require a non-zero size][alloc].
107107

108108
Note that references to ZSTs (including empty slices), just like all other
109-
references, must be non-null and suitably aligned. Dereferencing a null or
110-
unaligned pointer to a ZST is [undefined behavior][ub], just like for any other
111-
type.
109+
references, must be non-null and suitably aligned. However, loading or storing
110+
through a null pointer to a ZST is not [undefined behavior][ub], unlike
111+
pointers to other types.
112112

113113
[alloc]: ../std/alloc/trait.GlobalAlloc.html#tymethod.alloc
114114
[ub]: what-unsafe-does.html

0 commit comments

Comments
 (0)