C++'s complement of true is true, except when GCC says it's false

The complement of true is true, except when it's false

C++'s complement of true is true, except when GCC says it's false

A standards proposal for bitmask operations on enums leads to a deep dive into C++ integer promotion quirks. Integral promotion forces small types up to int, and boolean conversion maps any nonzero value to true. So ~true becomes true. But GCC disagrees for enums backed by bool, truncating instead of converting, and unscoped enums can trigger undefined behavior when bitwise results fall outside their value range.

There you have it, the complement of true is true, or spelled in C++ static_cast<bool>(~true) == true.

More from this day

2026-10-06