Skip to content

#if: two unary operators in a row silently evaluate to false #727

Closed

Description

@danmar

When two unary operators (!, ~, -, +) follow each other in an #if expression, the whole condition is false and no error is
reported.

#if !!1
yes
#else
no
#endif

gcc/clang: yes. simplecpp: no, with no error or warning.

More examples where gcc/clang say true and simplecpp says false:

Expression gcc/clang simplecpp
!!1 true false
!-0 true false
!+0 true false
!~-1 true false
- -1 true false
-!0 true false
-~0 true false
~!0 true false
+-1 == -1 true false
1 && !-0 true false
!-X (X not defined) true false

Expressions whose correct result is false, such as !-1, !!0 and ~~0, also give false, but only by coincidence.

With parentheses around the inner operation the result is correct. For example, !(-0) and !(!1) are both true.

Activity

  1. added a commit that references this issue on Nov 9, 2026
    a62b8ee
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