In C++ the expression ~true does not yield false as one might expect from a simple bitwise flip. Instead, the language promotes the bool value to an integral type before performing the complement operation. The value true (1) becomes an int, its bitwise complement is –2 under two’s‑complement arithmetic, and converting that int back to bool follows the boolean conversion rule: any non‑zero value becomes true. Consequently static_cast<bool>(~true) evaluates to true, a fact confirmed by the primary source which walks through the corresponding assembly output.

When the same operation is applied to a scoped enum whose underlying type is bool and annotated with [[std::bitmask_type]], the expected result according to the standard is also true. The enum’s bitwise complement operator first converts the enum to its underlying bool, promotes that bool to int, computes the complement (‑2), and then casts the int back to the enum type. Clang and MSVC perform the final cast by applying boolean conversion, yielding true. GCC, however, deviates: it truncates the int value to its lowest bit (‑2 → 0) before casting, producing false. This discrepancy is documented in the primary source, which shows divergent Godbolt links for the two behaviours.

A related pitfall arises with unscoped enums that lack a fixed underlying type. Here the complement operator can produce a value outside the enum’s representable range, and casting that value back to the enum type invokes undefined behaviour. For example, an enum nums {zero, one, two, three} has an underlying unsigned int; ~one yields ‑2 as an int, but casting ‑2 back to nums is out of range, which the standard flags as undefined behaviour. The primary source explains this risk and notes that the problem only affects plain enums without an explicit underlying type, since scoped enums and those with a fixed underlying type inherit a well‑defined range.