{
  "id": 11922032,
  "title": "The complement of true is true, except when it's false",
  "url": "https://urgent.news/2026/10/04/the-complement-of-true-is-true-except-when-its-false",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-04T12:30:26.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://dryperspective.github.io/posts/complement-of-true/"
  },
  "original_language": "en",
  "account": "The complement of true, in most cases, is true. However, there is an exception when it comes to bool. In C++, when you perform a bitwise complement operation on true and then cast the result back to a bool, the outcome is true. This is because the boolean conversion truncates the value, replacing the discarded bit pattern with true. The same happens when you try to evaluate the complement of true and cast the result to a bool – the result is always true.\n\nThe situation becomes more complicated when using enums as bitmasks. Enums can be defined with any integral type as their underlying type, including bool. To perform bitwise complement operations on enums, a template function is typically used. This function converts the enum to its underlying type, applies the bitwise operation, and then casts the result back to the enum. However, this can lead to confusion as the result of the complement operation may not be what is expected.\n\nWhen using gcc, the result of the complement operation on an enum may differ from the expected result. For example, if an enum is defined with bool as its underlying type, gcc will truncate the result to the lowest bit rather than perform a boolean conversion. This means that even values will result in bool::FALSE, while odd values will result in bool::TRUE. This behavior is specific to enum types and not directly applicable to bool.\n\nOn the other hand, compilers like Clang and MSVC evaluate the result of complement-and-cast operations consistently, following the standard rules. This means that the complement of true and the complement of any enum value will always result in true.\n\nOne potential issue arises when using an unsigned int as the underlying type for an enum. In this case, the integral promotion rules introduce a new vector for undefined behavior. If you try to perform a complement operation on an enum value using an unsigned int as its underlying type, the result may fail to compile. This is because the comparison reduces to a value that is not equal to zero, leading to a static assertion failure.",
  "summary": null,
  "key_points": [
    "Complement of true is true in most cases",
    "Exception occurs when complementing bool in C++",
    "Result varies with compiler and enum underlying type"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}