Weird codegen bug
Walter Bright
newshound2 at digitalmars.com
Fri Jun 14 20:11:01 UTC 2019
On 6/13/2019 4:28 AM, RazvanN wrote:
> import std.stdio : writeln;
>
> void main()
> {
> int a = 7;
> int b = 9;
>
> /* some code later */
>
> *(&a + 1) = 2;
> writeln(b);
> writeln(b);
> }
>
> This code prints:
>
> 9
> 2
>
> with latest version of dmd. Is this a bug or am I missing something? For the
> record,
> gdc prints (as expected):
>
> 2
> 2
>
It's undefined behavior to access memory beyond the boundaries of the memory
object pointed to:
https://github.com/dlang/dlang.org/pull/2649/files#diff-2bcc1b9af1e2da4f63bfda4b26f114a2R90
in an update to the spec that nobody sees fit to pull :-(
More information about the Digitalmars-d
mailing list