Skip to content

#if true evaluates to false in C++ and C23 #711

Closed

Description

@danmar

In #if and #elif expressions, simplecpp treats true and false like any other unknown name and replaces them with 0. So #if true is false.

In C++, true and false are keywords. The standard says they are not replaced with 0 in #if expressions; they evaluate to 1 and 0 ([cpp.cond]). C23 made them keywords too, and they also evaluate to 1 and 0 in #if (C23
§6.10.2).

Example

#if true
yes
#else
no
#endif
  • Expected (gcc -E -std=c++20 or -std=c23): yes
  • Actual (simplecpp): no

Activity

  1. added a commit that references this issue on Nov 6, 2026
    d5e6da6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions