Skip to content

#if: an operator with a missing operand silently evaluates to false #731

Closed

Description

@danmar

When an operator in an #if expression is missing an operand, simplecpp does not report an error. The condition silently evaluates
to false.

#if (1 +)
yes
#else
no
#endif

gcc/clang: error, operator '+' has no right operand. simplecpp: no, with no error or warning.

Binary operators

Expression gcc/clang simplecpp
1 + error false
(1 +) error false
(1 +) + 1 error false
* 1 error false
(* 1) error false
1 + * 2 error false
1 << error false
(1 ==) error false
1 & error false
(1 &&) error false
|| 1 error false

The same happens for -, /, %, <, ^ and |.

Unary operators

Expression gcc/clang simplecpp
! error false
(!) error false
- error false
~ error false

?:

?: already reports "invalid expression" when the missing operand is at the start or end of the expression, but not when it is next
to a parenthesis:

Expression gcc/clang simplecpp
? 1 : 2 error error
(? 1 : 2) error false
1 ? 2 : error error
(1 ? 2 :) error false
(1 ? 2 3) error false
(1 ? : 2) error false

Activity

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