| ▲ | 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. | ||||||||
| ||||||||