3 ms·
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.
by zajio1am 5y ago
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.
- MauranKilom 5y ago(Or templates, in the C++ case. Think of all the inlined iterator functions...)
- Too 5y agoIn 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.
- UncleMeat 5y agoWhy 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.