File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -608,14 +608,31 @@ $(GNAME VoidInitializer):
608
608
used before it is set, undefined program behavior will result.
609
609
)
610
610
611
- $(UNDEFINED_BEHAVIOR If a void initialized variable's value is
612
- used before it is set, the behavior is undefined .
611
+ $(IMPLEMENTATION_DEFINED If a void initialized variable's value is
612
+ used before it is set, the value is implementation defined .
613
613
614
614
---
615
+ import std.stdio;
615
616
void foo()
616
617
{
617
618
int x = void;
618
- writeln(x); // will print garbage
619
+ writeln(x); // will likely print garbage
620
+ }
621
+ ---
622
+ )
623
+
624
+ $(UNDEFINED_BEHAVIOR If a void initialized variable is a reference type
625
+ and its value is dereferenced before it is set, the behavior is undefined.
626
+ Such initializations are not allowed in `@safe` code.
627
+
628
+ ---
629
+ void foo()
630
+ {
631
+ int* p = void;
632
+ *p = 3; // undefined behavior
633
+ int x;
634
+ p = &x;
635
+ *p = 3; // ok
619
636
}
620
637
---
621
638
)
You can’t perform that action at this time.
0 commit comments