This is an example to illustrate my question which involves some much more complicated code that I can\'t post here.
#include
int main()
{
One thing your example doesn't consider is optimisation. a
is set in the loop but never used, and an optimiser could work this out. As such, it is legitimate for the optimiser to discard a
completely, and in that case all undefined behaviour vanishes like a boojum's victim.
However of course this itself is undefined, because optimisation is undefined. :)