One of the requirements for clang — the new C++ compiler — was to provide the user with detailed information about errors. Let’s look at a small example.

[]double UniversalGravitation(double G, double mass1, double mass2, double distance) {     double F = G * ((mass1 * mass2)/(distance * dsitance));     return F; }

There’s a typo in the identifier here. So what will clang show us?

consoleoutput

First, it thoughtfully underlines the spot in the long expression: exactly which identifier it considers unfamiliar. Second, it politely suggests a possible fix. Let’s remember what similar messages look like in Microsoft Visual Studio 2010. (Though Visual Studio 2010 does deserve some praise: it highlights this type of error while you’re still editing.)

consoleoutputvs2010

gcc shows something like this:

<font size="2" face="Consolas">/tmp/webcompile/_13952_0.cc: In function 'double UniversalGravitation(double, double, double, double)': /tmp/webcompile/_13952_0.cc:3: error: 'dsitance' was not declared in this scope</font>

You can read about other capabilities of the clang compiler’s diagnostic mechanism in the documentation: Expressive Diagnostics. The cases where it finds errors in unexpanded macros or in typedefs are very interesting.

I’m already waiting for compilers in the future to fix errors themselves. And then write code themselves, too.