Skip to content

[SUGGESTION] Support (some) C++ alternative tokens #304

Description

@JohelEGP

I prefer writing (and, or) to (&&, ||). Currently, they're treated as identifiers. So cppfront emits an error if used C++1-correctly (x = y and z;, 3 identifiers in a row is ill-formed), or emits bad C++1 code (x = and;).

https://github.com/hsutter/cppfront/wiki/Design-note%3A-Postfix-unary-operators-vs-binary-operators talks about "alternative tokens". It seems they were supported at some point before this repository was published.

Will your feature suggestion eliminate X% of security vulnerabilities of a given kind in current C++ code? No (my guess).

Will your feature suggestion automate or eliminate X% of current C++ guidance literature? No (my guess).

Describe alternatives you've considered.

  1. Rejecting the suggestion. It goes against https://github.com/hsutter/cppfront/blob/main/.github/ISSUE_TEMPLATE/suggestion.md?plain=1#L10-L13 (it'd be easier to read the source if https://sembr.org/ was followed).
  2. Recognize them and
  • diagnose an use and suggest its alternative, or
  • try to emit valid C++ identifiers in their place (e.g., renaming to _and, with no portable way to name them from C++1).

Activity

  1. msadeqhe commented on Mar 30, 2023

    @msadeqhe

    I think logical operators and, or and not are completely different from bitwise operators bitand, bitor, xor and compl, because bitwise operators calculate the result of expressions just like +, -, *, / and other arithmetic operators but logical operators are for decision making similar to is and as keywords in C++2. Therefore it's reasonable to have &&, || and ! as keywords and, or and not similar to is and as, but bitwise operators &, |, ^ and ~ are arithmetic operators and they should not be keywords.

  2. AbhinavK00 commented on Mar 30, 2023

    @AbhinavK00

    I think having the bitwise operators spelled out would eliminate more ambiguity than spelling out the logical operators. For example:

    a&&b; //what if a and b are not bool? This is the kind of context cpp2 tries to eliminate ig?

    That would also reserve ^ for pointer deference(wow!!) and could also eliminate ambiguity between bit shift operators and when writing template template parameters.

  3. JohelEGP commented on Mar 30, 2023

    @JohelEGP
    ContributorAuthor

    not is another one I use. So much that I have Clang-Format insert a space after ! so that it stands out in case I forget to use it (! x -> not x).

    In Cpp2, they should be keywords, not alternative tokens. Then there's no chance you can use it weirdly, like in Cpp1 (e.g. x and = y;).

  4. AbhinavK00 commented on Mar 30, 2023

    @AbhinavK00

    How would we write x != y with this change? Or is the plan to support both tokens?

  5. JohelEGP commented on Mar 30, 2023

    @JohelEGP
    ContributorAuthor

    I did notice that not_eq is a thing when checking out https://eel.is/c++draft/lex.digraph as I wrote this proposal.

    I'm not proposing banning using operators. So you choose to write it however you like. Including using std::not_equal(x, y).

  6. JohelEGP commented on Apr 4, 2023

    @JohelEGP
    ContributorAuthor

    There's some mentions of an and keyword and more starting at #152 (comment).

  7. JohelEGP commented on Apr 7, 2023

    @JohelEGP
    ContributorAuthor

    I've opened #328 for the lack of diagnostics.
    I'm closing this in favor of simplicity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions