Skip to content

#if: not and compl are only recognized at the start of an expression or after ( #729

Closed

Description

@danmar

In C++ code, not and compl are alternative spellings of ! and ~. In an #if expression, simplecpp only treats them as
operators when they appear at the start of the expression or after (, and are followed by a number or a name. Other uses give a
wrong result without an error, or an error where g++ accepts the expression.

#if 1 && not 0
yes
#else
no
#endif

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

After a binary operator or ? / :

Expression g++/clang++ simplecpp
1 && not 0 true false
1 and not 0 true false
0 || not 0 true false
1 == not 0 true false
0 ? 0 : not 0 true false
1 ? not 0 : 0 true false

Next to another unary operator

Expression g++/clang++ simplecpp
not not 1 true false
not -0 true false
not ~-1 true false
not !0 == 0 true false
compl compl 1 == 1 true false
compl -1 == 0 true false
compl -1 + 1 == 0 false true
-compl 0 == 1 true false

Followed by (

Expression g++/clang++ simplecpp
not (0) true error: undefined function-like macro invocation: not( ... )
not(0) true error: undefined function-like macro invocation: not( ... )
compl (0) == -1 true error: undefined function-like macro invocation: compl( ... )

At the start of an expression not 0, (not 0), not 0 && 1 and compl 0 work as expected.

Activity

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