Is this uninitialised variable usage undefined behaviour
Yes.
The behaviour of reading an indeterminate value is undefined. This code copy initialises the argument thing
using x
which hasn't yet been initialized, thus having an indeterminate value and thus behaviour is undefined.
Is this code undefined behaviour ?
Yes.
Specifically this ? "while (Thing* x = getNext(x))"
Yes, specifically this has UB.
does the x get initialised to zero because of a rule in the standard
No. There is no such rule that would say x
would be zero initialised in this context.
or is it just lucky or the compiler is doing it anyway but shouldn't be relied upon?
The behaviour is undefined. If it was the behaviour of the program that alerted you to the conclusion that it might be undefined, then you could consider yourself to have been lucky. You can improve your luck by enabling compiler warnings:
warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]