Can xor have UB/IB in C++?

146 Views Asked by At

Seeing that the answers to these questions (this and this one) talk about C, I cannot extend this knowledge to C++, so this is not a duplicate, but a clarification.

Update: I'm only talking about C++. If something is defined in C, it does not mean that it is defined in C++ and vice versa, which is why I am asking this question.

1

There are 1 best solutions below

2
On

According to Bitwise logic, xor can not have UB or IB in results of integer types.

The xor operator performs usual arithmetic conversions on both operands of other types that may lead undefined behavior.