-
Notifications
You must be signed in to change notification settings - Fork 260
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
[BUG] Diagnose use of C++1 alternative tokens #328
Comments
For the first reproducer, I noticed that for GCC, the error message points to the Cpp2 source, so the marker is off.
GCC:
|
It doesn't diagnose most uses of reserved words as variable names. For example, all of these are passed through to be diagnosed by the C++1 compiler:
|
FYI, both of those Compiler Explorer links contain the Cpp2 code in a C++ environment, and there are a bunch of other files loaded in various panes. |
It'd be OK to just diagnose alternative tokens where their primary token would be valid. Like the second reproducer.
Yes, those bring Cpp2 and C++ modules support. |
That would be interesting. I wonder if it would be more work to just support them or to diagnose them. Have you seen anything from Herb that says that he's not planning to support them?
Okay, but the main file is still marked as C++ instead of CppFront, so I have to copy the contents, change the type to CppFront, and paste the text. I don't know if this is a CE bug with the links, or if something else is weird. |
Not quite. #152 (comment) mentions
And the design note linked below that, as #304 puts it:
CE's not bugged. CE's Cpp2-cppfront language option only compiles with |
It would be good to hear from him on whether he thinks they should still be supported.
Interesting. BTW, that transpile to C++1 and compile the converted file in CE was one of the things that Herb called out at the end of his keynote as something he'd like someone to help him with. (That was before he knew that the transpile stage had been put up on CE during his talk.) |
The CMake module used was added to the wiki: #4 (comment). But unlike CE's support for Cpp2, I have to manually update |
Re Godbolt Compiler Explorer: Yes, I'd love for there to be a way in CE to compile Cpp2 using cppfront + a choice of C++ compiler as the second compiler (or for now even just one hardwired compiler). Re alternative spellings for operators:
I'm more inclined to Option 2... it's similar to how I already rename
A non-option is to support the alternative spellings with their current meaning, because they violate "don't have two ways to say the same thing"... 😁🦆🏃 (trying an emoji version of the old |
Option 2 FTW! Thanks. |
Thank you. I see that cb8c1c5 actually appends |
IMO Option 2 increases complexity for language introp with C, C++ and other programming languages, because the programmer has to know what will be the renamed Option 1 is a more straight solution. Programmers will choose their own variable name |
That's likely to break reflection. What about this alternative? int x = algo().__cpp2_and; // C++1. OK, renaming guaranteed to work. That could be guaranteed by Cpp2 to work. So it'd work using a non-transpiler Cpp2 compiler. |
Thanks! I agree, using the |
I didn't realize I could close them. Now it looks much cleaner: https://cpp2.godbolt.org/z/KdW89o475.
Now
After the above, we have this. |
Another thing there's no need to support anymore and that we shouldn't have to teach... these haven't been needed since the 1980s. Normally we don't have to teach things that compilers treat as errors, because they don't compile, but this is a case where the error is surprising and so we still have to teach it (i.e., when users trip across trying to use a common word like `and` as a variable name and wonder why it's an error and then it's a whole thing again)
The use of C++1 alternative tokens lead to invalid Cpp2 or generated C++1 depending on use.
Minimal reproducer (https://godbolt.org/z/4dT5hre58):
Commands:
cppfront x.cpp2 clang++17 -std=c++2b -I $CPPFRONT_INCLUDE_DIR x.cpp
Expected result: Diagnose
and
as reserved.Actual result and error:
Generated C++1
Minimal reproducer (https://godbolt.org/z/WMzzjhGWM):
Commands:
Expected result: Diagnose
and
as reserved, suggest&&
.Actual result and error:
The text was updated successfully, but these errors were encountered: