Remix.run Logo
yongjik 8 hours ago

I think UB doesn't have much to do with this bug after all.

The original code defined a struct with two bools that were not initialized. Therefore, when you instantiate one, the initial values of the two bools could be anything. In particular, they could be both true.

This is a bit like defining a local int and getting surprised that its initial value is not always zero. (Even if the compiler did nothing funny with UB, its initial value could be anything.)

baobun 5 hours ago | parent [-]

> The original code defined a struct with two bools that were not initialized. Therefore, when you instantiate one, the initial values of the two bools could be anything. In particular, they could be both true.

Then reading from that struct like in OP constitutes UB.

yongjik 5 hours ago | parent [-]

Well yes, that would be UB, but even if the C++ compiler had no concept of UB, it would still be wrong code.