Logo

Blog


Happy 3 year Birthday C++ Insights

Today it is three years since I published C++ Insights.

Happy Birthday C++ Insights

The project helped me to get a totally new understanding of the language. In addition, I developed okay skills with Clang's AST.

I had the opportunity to talk about C++ Insights at various conferences and meetups:

  • "C++ Insights: How stuff works, C++20 and more!", C++ now, May 06
  • "C++ Insights: How stuff works, C++20 and more!", Meeting C++ online, April 08
  • "C++ Insights: How stuff works, Lambdas and more!", Cpp Europe, February 23
  • "C++ Insights", ESE Kongress, December 01, 2020
  • "C++ Insights: How stuff works, Lambdas and more!", OOP, February 06, 2020
  • "C++ Insights: How stuff works, Lambdas and more!", MUC++, February 05, 2020
  • "C++ Insights: How stuff works, Lambdas and more!", ACCU Autum Conf, November 11, 2019
  • "C++ Insights: See your source code with the eyes of a compiler", NDC { TechTown }, September 05, 2019

While I was putting this list together, I realized how many it already has been. For slides or videos, head over to my talks page.

At this point, I like to thank every one of you who supported the project and me! Especially with some very kind emails telling me how much C++ Insights is appreciated by the community.

Last year I made the switch from TravisCI to GitHub Actions, which leads to much better turnaround times.

What can the future bring?

Match at TU level

Well, I still like to get rid of the initial AST matchers. C++ Insights should match on the TU level and by that match all statements. It looks like the matchers are stable because I haven't received issue reports that certain constructs are not matched. However, I would reduce the source code a bit which is good. Not having to worry about something unintentionally left out would also a big relief. I hear you thinking, "so what you are waiting for?". The reason is that matching at the TU level brings other issues. The way structured bindings are represented in the AST is one example. Here is an example (godbolt):

1
2
3
4
5
6
7
8
struct Point {
    int x;
    int y;
};

Point pt{2,3};

auto& [a, b] = pt;

The resulting reduced AST is this:

1
2
3
4
5
|-BindingDecl <line:8:8> col:8 a 'int'
|-BindingDecl <col:11> col:11 b 'int'
`-DecompositionDecl <col:1, col:16> col:7 referenced 'Point &' cinit
  |-BindingDecl <col:8> col:8 a 'int'
  `-BindingDecl <col:11> col:11 b 'int'

As you can see, the BindingDecl occurs before the DecompositionDecl itself. I need the DecompositionDecl to show the special internal object the compiler creates for us. I'm not 100% sure, but I think I saw other issues like this.

Show constexpr evaluations

Another thing I'm looking into from time to time is to show the values of a constexpr evaluation. While I was writing this post, I put together this example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
constexpr int Simple()
{
    return 3;
}
constexpr auto f = Simple();


constexpr auto Difficult()
{
    struct X { int i; int z; };

    return X{3,4};
}

constexpr auto ff = Difficult();

Much to my surprise, I discovered that Clang 12 knows and shows the values in the AST (see godbolt). It did not do so in Clang 10. I have a draft implementation for a long time invoking the constexpr evaluator. However, there is one issue. In the code above, Simple as the name suggests, is simple. It returns a single int. The function Difficult is, as the name implies, not simple. Here a struct is returned. I need to go through all the possibilities of APValue and transform them into C++ code. I will take another shot at it.

Coroutines

One feature that seems to have a lot of interest is coroutines. As I wrote in an earlier post, they are special. I do have a draft for them, but I need to clean some things up and see whether this is really what you want.

C++ Insights @ YouTube

Exactly one year ago, I launched a YouTube channel for C++ Insights. I post a new episode there every month. This was fun so far, and I hope you enjoyed one or the other episode as well. For me, it is a challenge, as this is not really my preferred form. However, I like some challenges, and I hope it helps you as well. I will keep this up.

While we are talking about YouTube, I decided to do something special this month to celebrate C++ Insights' birthday as well as the one-year YouTube channel. Instead of a regular episode, I will do a live stream! Pretty amazing for me. I've never done one before. You can subscribe here: C++ Insights - Episode 14: Happy Birthday C++ Insights

The idea is that you can ask me questions about C++ Insights, tell me feature requests, or other things you like to see in C++ Insights. I will prepare to show you some internals of C++ Insights and a bit of the current coroutine status. Be sure not to miss this! I aim for 30 - 60 minutes.

I hope you will have another fantastic year with C++ Insights. In case you like to support the project, consider becoming a Patreon or, of course, contribute with code.

This leaves me to say THANK YOU for your support!!!

Andreas