Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JohelEGP opened this issue Mar 28, 2023 · 7 comments
Closed

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

JohelEGP opened this issue Mar 28, 2023 · 7 comments

Comments

@JohelEGP
Copy link
Contributor

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).
@msadeqhe
Copy link

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.

@AbhinavK00
Copy link

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.

@JohelEGP
Copy link
Contributor Author

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;).

@AbhinavK00
Copy link

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

@JohelEGP
Copy link
Contributor Author

JohelEGP commented Mar 30, 2023

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).

@JohelEGP
Copy link
Contributor Author

JohelEGP commented Apr 4, 2023

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

@JohelEGP
Copy link
Contributor Author

JohelEGP commented Apr 7, 2023

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

@JohelEGP JohelEGP closed this as completed Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants