Most of this post is about improvements I’ve been making and merging over the year-end holidays, and an increasing number of contributions from others via pull requests to the cppfront repo and in companion projects. Thanks again to so many of you who expressed your interest and support for this personal experiment, including the over 3,000 comments on Reddit and YouTube and the over 200 issues and PRs on the cppfront repo!
10 design notes
On the cppfront wiki, I’ve written more design notes about specific parts of the Cpp2 language design that answer common questions. They include:
- Broad strategic topics, such as addressing ABI and versioning, “unsafe” code, and aiming to eliminate the preprocessor with reflection.
- Specific language feature design topics, such as unified function call syntax (UFCS),
const, and namespaces.
- Syntactic choices, such as postfix operators and capture syntax.
- Implementation topics, such as parsing strategies and and grammar details.
117 issues (3 open), 74 pull requests (9 open), 6 related projects, and new collaborators
I started cppfront with “just a blank text editor and the C++ standard library.” Cppfront continues to have no dependencies on other libraries, but since I open-sourced the project in September I’ve found that people have started contributing working code — thank you! Authors of merged pull requests include:
- The prolific Filip Sajdak contributed a number of improvements, probably the most important being generalizing my UFCS implementation, implementing more of
asas described in P2392, and providing Apple-Clang regression test results. Thanks, Filip!
- Gabriel Gerlero contributed refinements in the Cpp2 language support library,
- Jarosław Głowacki contributed test improvements and ensuring all the code compiles cleanly at high warning levels on all major compilers.
- Konstantin Akimov contributed command-line usability improvements and more test improvements.
- Fernando Pelliccioni contributed improvements to the Cpp2 language support library.
- Jessy De Lannoit contributed improvements to the documentation.
Thanks also to these six related projects, which you can find listed on the wiki:
- Conan recipe for cppfront by Fernando Pelliccioni.
- /modern-cmake/cppfront, a modern CMake (3.23+) build for cppfront.
- /JohelEGP/jegp.cmake_modules/#jegpcpp2, a CMake module to build Cpp2 source files.
- Meson support for cppfront by Jussi Pakkanen, creator of Meson.
- Sublime syntax highlighting for Cpp2 by Andrew Feldman.
- Visual Studio Code syntax highlighting for Cpp2 by Elazar Cohen. (I use this by default.)
Thanks again to Matt Godbolt for hosting cppfront on Godbolt Compiler Explorer and giving feedback.
Thanks also to over 100 other people who reported bugs and made suggestions via the Issues. See below for some more details about these features and more.
Here are some highlights of things added to the cppfront compiler since I gave the first Cpp2 and cppfront talk in September. Most of these were implemented by me, but some were implemented by the PR authors I mentioned above.
Roughly in commit order (you can find the whole commit history here), and like everything else in cppfront some of these continue to be experimental:
- Lots of bug fixes and diagnostic improvements.
- Everything compiles cleanly under MSVC
- Enabled implicit move-from-last-use for all local variables. As I already did for
- After repeated user requests, I turned
-s(null/subscript dynamic checking) on by default. Yes, you can always still opt out to disable them and get zero cost, Cpp2 will always stay a “zero-overhead don’t-pay-for-what-you-don’t-use” true-C++ environment. All I did was change the default to enable them.
- Support explicit
forwardof members/subobjects of composite types. For a parameter declared
forward x: SomeType, the default continues to be that the last use of
xis automatically forwarded for you; for example, if the last use is
call_something( x );then cppfront automatically emits that call as
call_something( std::forward<decltype(x)>(x) );and you never have to write out that incantation. But now you also have the option to separately forward parts of a composite variable, such as that for a
forward x: pair<string, string>>parameter you can write things like
do_this( forward x.first )and
do_that( 1, 2, 3, forward x.second ).
isnow supports asking whether this is an instantiation of a template (e.g.,
x is std::vector), and it supports comparing values (e.g.,
x is 14) and using predicates (e.g.,
x is (less_than(20))invoking a lambda) including for values inside a
x is 42where
- Regression test results for all major compilers: MSVC, GCC, Clang, and Apple-Clang. All are now checked in and can be conveniently compared before each commit.
- Finished support for
>>=expressions. In today’s syntax, C++ currently max-munches the
>>=tokens and then situationally breaks off individual
>tokens, so that we can write things like
vector<vector<int>>without putting a space between the two closing angle brackets. In Cpp2 I took the opposite choice, which was to not parse
>>=as a token (so max munch is not an issue), and just merge closing angles where a
>>=can grammatically go. I’ve now finished the latter, and this should be done.
- Generalized support for UFCS. In September, I had only implemented UFCS for a single call of the form
xcould not be a qualified name or have template arguments. Thanks to Filip Sajdak for generalizing this to qualified names, templated names, and chaining multiple UFCS calls! That was a lot of work, and as far as I can tell UFCS should now be generally complete.
- Support declaring multi-level pointers/
- Zero-cost implementation of UFCS. The implementation of UFCS is now force-inlined on all compilers. In the tests I’ve looked at, even when calling a nonmember function
f(x,y), using Cpp2’s
x.f(y)unified function call syntax (which tries a member function first if there is one, else falls back to a nonmember function), the generated object code at all optimization levels is now identical, or occasionally better, compared to calling the nonmember function directly. Thanks to Pierre Renaux for pointing this out!
- Support today’s C++ (Cpp1) multi-token fundamental types (e.g.,
signed long long int). I added these mainly for compatibility because 100% seamless interoperability with today’s C++ is a core goal of Cpp2, but note that in Cpp2 these work but without any of the grammar and parsing quirks they have in today’s syntax. That’s because I decided to represent such multi-word names them as a single Cpp2 token, which happens to internally contain whitespace. Seems to work pretty elegantly so far.
- Support fixed-width integer type aliases (
u64, etc.), including optional
I think that this completes the basic implementation of Cpp2’s initial subset that I showed in my talk in September, including that support for multi-level pointers and the multi-word C/C++ fundamental type names should complete support for being able to invoke any existing C and C++ code seamlessly.
Which brings us to…
Next, as I said in the talk, I’ll be adding support for user-defined types (classes)… I’ll post an update about that when there’s more that’s ready to see.
Again, thanks to everyone who expressed interest and support for this personal experiment, and may you all have a happy and safe 2023.