Comment

Comment by JonChesterfield

The amazing part about examples like that is people read them, check that the compiler really does work on that basis, and then continue writing things in C++ anyway. Wild.

Suppose I should expand on this. The idea seems to be either 1/disbelief - compilers wouldn't really do this or 2/ infallibility - my code contains no UB.

Neither of those positions bears up well under reality. Programming C++ is working with an adversary that will make your code faster wherever it can, regardless of whether you like the resulting behaviour of the binary.

I suspect rust has inherited this perspective in the compiler and guards against it with more aggressive semantic checks in the front end.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton