C++ Annotated: December 2020. Now Also Available as a Podcast!
Welcome to the newest edition of C++ Annotated and its companion, the No Diagnostic Required YouTube show! They are now available in the following formats:
- The regular digest published monthly on this blog (use the form on the right to subscribe).
- C++ Annotated emails, which you can subscribe to by filling out this form.
- The No Diagnostic Required show here in the blog or on YouTube. To stay tuned, follow us on Twitter.
- You should be able to find us in most podcast players by searching for "No Diagnostic Required" (see the list on our website).
- 20 years of LLVM
- More 20s. C++20 is officially published!
- C++20’s 3-way comparison
- Boost 1.75 released
- Two’s Complement (podcast)
- CoSy Tech (new systems language conference)
- CLion AMA on Reddit
- An interview question that could easily trap you
Watch the new episode of No Diagnostic Required below, or just read on!
20 years of LLVM
How long have you been aware of the LLVM project, or maybe contributed to it? Turns out it started a full 20 years ago! All are invited to share their experiences with LLVM in the dedicated tweet that celebrates the date. Don’t forget to use the #CelebrateLLVM hashtag.
Because of that thread, people often start with LLVM as a backend for their programming language, such as Event, a language for rule-based complex-event processing on distributed networks, or Julia, a language for technical computing. At JetBrains, we’re also building Kotlin/Native for Native on top of the LLVM platform.
But LLVM is much more than a compiler backend. It’s also a set of various tools like analyzers, formatter, debugger, linker, an implementation of the standard library, OpenCL, OpenMP, and more. It’s impressive to see the ecosystem growing and getting more contributions from the community and more developers relying on LLVM in all sorts of projects.
Our users often ask us how to set up Clang on Windows without Microsoft Visual Studio installed. Clang from the LLVM repo is built using MSVC, and all the built-in macros and include search paths are set up for use with Visual Studio. However, the MSYS2 Clang works with the mingw-w64 toolchain nicely. Read on about how to configure it.
More 20s. C++20 is officially published!
While C++20 is already in use in many projects, the newest standard was officially published in December. Which means you can now officially buy its final version!
If you are curious about what the final set is like, check out the overview at cppreference, for example. There are many awesome things inside, from big ones like Coroutines (
co_yes!), Modules, and Concepts to language features like the 3-way comparison, feature test macros, constevel/constinit, new attributes (
[[no_unique_address]] is definitely great!), as well as dozens of library features like Ranges, formatting library, Calendar, and TimeZone. And I just remembered a nice old thread on Reddit discussing what folks are most excited about in C++20. What are your favorites? Let us know in the comments!
There are many talks and articles on each of these new additions, but more important is what exactly is supported in the compiler you are using. That means it’s time to check out the recent compiler releases and implementation status (for Clang, for GCC, for MSVC).
C++20’s 3-way comparison
Chances are you’ve heard about the new 3-way comparison, also known as the spaceship operator. You might even know it makes the comparison implementation in C++ much more convenient. But how? And what problem does it address?
The biggest benefit is probably that you can implement less if you customize the comparison. Before C++20, you had to implement two equality operators and four relational operators, and even more if you compared different types. Now just two are enough: equality and the new spaceship operator. And it’s not just that you save some time coding, but now member comparison operators can handle heterogeneous comparisons, too!
Igor Akhmetov spent the whole 2020.3 release cycle implementing support for the 3-way comparison operator in ReSharper C++. In this article, he describes what ReSharper C++ brings to its users in terms of support, such as the updated Create Operator from Usage action, quick-fixes to add a missing
<compare> header, and more.
Boost 1.75 release
Boost is often called a playground for the future C++ standard updates, which provides an interesting perspective from which to view its release. Version 1.75 that came out in December brought three new libraries to Boost:
- JSON: for JSON parsing and serialization in C++11. Interestingly, it can be header-only and doesn’t have Boost dependencies (without Boost it requires C++17).
- LEAF: an error-handling library for C++11. Its biggest benefits include: no dynamic memory allocations, the transport of arbitrary error types independent of the call stack depth (the library is designed with the use case of a trivial success-or-failure flow in mind, when callers of the function do not handle the errors), and an ability to use the library w/o exception handling. And again, a single-header format w/o dependencies is possible.
PFR: a C++14 library for very basic reflection. The best thing about it is that it gives you access to structure elements by index and provides other
std::tuple-like methods for user-defined types – without macro or boilerplate code! And again, it’s a header-only library without dependencies on Boost itself. Note that pre-C++14 compilers are not supported.
Now let’s talk about a few events and shows that happened recently.
Two’s Complement (podcast)
With so many of us being stuck at home for extended periods this year, more new podcasts are emerging from the community. Last month we launched No Diagnostic Required and mentioned TLB Hit and ADSP. This month we see Two’s Complement from Matt Godbolt and Ben Rady. It isn’t, strictly speaking, a C++ podcast, but given how well-known Matt is in the C++ community, I thought it was worth sharing. In the first episode – episode 0, of course – Ben and Matt talk about their early careers and how they got to where they are now.
CoSy Tech (New systems language conference)
Just as we reach podcast overload, we’ve also been overloaded with conferences that are relevant to the C++ community for some time. So what better time to start another one? But CoSy Tech is a bit different. JeanHeyd Meneide, a.k.a. ThePhd, is introducing a conference for systems language programmers – so not just C++, but C, Rust, and even Lua and Zig. But, perhaps more significantly, he is prioritizing diversity and inclusion. That may not sound particularly unique these days. Other conferences, like C++ on Sea, have diversity and inclusion at the heart of their mission statement. But CoSy Tech – a collaboration between JeanHeyd and Shepherd Oasis – aims to take it further still. We wish JeanHeyd the best of luck.
CLion AMA on Reddit
In December 2020, the CLion team held a Q&A session on Reddit that was dedicated to the recent CLion 2020.3 release and our plans for 2021. Seven team members (and a few more behind the scenes) answered about 35 questions and participated in discussions spread over 118 comments in the threads under the post. We then posted a follow-up.
Interestingly, readers were very much interested in Meson and Bazel project models. According to our Developer Ecosystem study, these models account for 2-4% percent each of the overall usage. Bazel seems to be steadily growing over the years and is mostly driven by Google. Meson is used in such projects as AQEMU (a Qt GUI for QEMU virtual machines), GTK+ (the multi-platform toolkit used by GNOME), Pacman (a package manager for Arch Linux), and Wayland. While CLion doesn’t have any immediate plans on either of these, the compilation database workaround for Meson and a Google plugin for Bazel seem like workable options for the time being.
Another interesting aspect is the interest in cross-debuggers, like between Python and C++ or between Java and C++. We’re looking to identify the trending use cases, apart from the obvious Android and NDK specific one for Java/C++, and things like Cython for Python/C++. If you know of any others, please let us know in the comments.
An interview question that could easily trap you
This might be (at first glance) an obvious interview question, but as the reddit thread confirms, it’s much trickier than many might imagine.
There’s code dereferencing a
null pointer and it’s wrapped in a
try-catch block. The
catch-branch is printing to the output stream. Do we get the output or not? Dereferencing a pointer is Undefined Behavior, according to the standard. But then it comes down to each compiler to implement this case, and that’s where the details can make a difference. An interesting observation is that a segmentation fault can still cause the corresponding message to be printed, instead of calling the C++ exception handler. Different behavior is still possible for MSVC, which has the
/EH flag that exactly specifies the exception-handling mechanism and can lead to
catch() actually catching both structured (asynchronous) and standard C++ (synchronous) exceptions.
That’s it for today. Enjoy the holidays, and we’ll see you in January!
The JetBrains C++ team
The Drive to Develop