Hacker News new | past | comments | ask | show | jobs | submit login

> Does that happen when the compiler assumes you'll never take branches that lead to UB, and then finds a path through your branches that more or less does nothing? Or can it happen even if you're not branching at all?

Yes and yes. How far it will propagate these backwards depends on the compiler.

> Is the compiler really allowed to produce a program that doesn't print?

Yes. A program which contains UB is illegal, there are no guarantees about any of its behaviour, including behaviour which precedes any possible actual invocation of UB, this is pointed rather clearly by the standard:

> However, if any such execution contains an undefined operation, this International Standard places no requirement on the implementation executing that program with that input (not even with regard to operations preceding the first undefined operation).




Good heavens! :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: