News for hackers. Stuff that matters.
Re:Near-duplicate features of C++ (2017) by ori_b on Thursday May 23, 2019 @11:01PM (#19998109)
This is not a valid program. The second line invokes undefined behavior. The compiler is legally allowed to replace the null dereference with code that sends your porn collection to your mother, and set the reference to 42.

If you get a null reference, this is by chance and not by design.

Re:Near-duplicate features of C++ (2017) by ahoka on Friday May 24, 2019 @07:56AM (#20000581)
> The compiler is legally allowed to replace the null dereference with code that sends your porn collection to your mother, and set the reference to 42.

Although no sane implementation would do this.

Re:Near-duplicate features of C++ (2017) by ori_b on Friday May 24, 2019 @03:13PM (#20004474)
No, but they may optimize out assigning to the reference at all, since assigning to it requires dereferencing a provably null pointer, which means that any future code is effectively meaningless.
Re:Near-duplicate features of C++ (2017) by setr on Friday May 24, 2019 @03:14PM (#20004487)
They wouldn't, but they could very well come to a different sane result on a particular architecture than they implementation/architecture you're on.

And that would be perfectly compiler-legal, and your code would have one free bug.