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

But such code might be generated by macros (or some code generator), in which case silent elimination of unnecessary code is expected and wanted behavior.



In this particular case the code is wrong and can be fixed easily by swapping the assignment and the comparison.

Likewise, code generators shouldn’t be generating this faulty code.

Raising compiler error here is the only right thing to do.

There are of course more ambiguous examples, though obvious examples like the one above are sadly way too common.


Why can't we say that the original code is wrong then? The whole point of having something be UB rather than implementation defined is because the language committee believes that it represents a bug in your program.


(Or templates, in the C++ case. Think of all the inlined iterator functions...)




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

Search: