I work at Red Hat on the GNU Compiler Collection (GCC). GCC 16 is about to be released, so I'm sharing some of the new features I worked on this year. Some changes are visible to users, while others improve the system more subtly.
New C++ error improvements
A well-known challenge for C++ developers is the readability of template-related error messages. C++ compilers tend to either provide too little information or spew screenfuls of text at you. Either way, the errors can be difficult to decipher.
GCC error messages have a hierarchical structure to them. In GCC 15, I added an experimental option that shows this structure as a collection of nested bullet points.
In GCC 16, this behavior is now the default. You can return to the previous behavior using -fno-diagnostics-show-nesting or -fdiagnostics-plain-output. I fixed several bugs and made use of the hierarchical structure in more places. For example, it is easy to get declarations and definitions out of sync when manually adding const to a parameter:
class foo { public: void test(int i, int j, void *ptr, int k); }; // Wrong "const"-ness of param 3. void foo::test(int i, int j, const void *ptr, int k) { }
In GCC 15, we emitted the following output:
<source>:8:6: error: no declaration matches 'void foo::test(int, int, const void*, int)' 8 | void foo::test(int i, int j, const void *ptr, int k) | ^~~ <source>:4:10: note: candidate is: 'void foo::test(int, int, void*, int)' 4 | void test(int i, int j, void *ptr, int k); | ^~~~ <source>:1:7: note: 'class foo' defined here 1 | class foo | ^~~
In GCC 16, we now emit this:
<source>:8:6: error: no declaration matches 'void foo::test(int, int, const void*, int)' 8 | void foo::test(int i, int j, const void *ptr, int k) | ^~~ • there is 1 candidate • candidate is: 'void foo::test(int, int, void*, int)' <source>:4:10: 4 | void test(int i, int j, void *ptr, int k); | ^~~~ • parameter 3 of candidate has type 'void*'... <source>:4:35: 4 | void test(int i, int j, void *ptr, int k); | ~~~~~~^~~ • ...which does not match type 'const void*' <source>:8:42: 8 | void foo::test(int i, int j, const void *ptr, int k) | ~~~~~~~~~~~~^~~ <source>:1:7: note: 'class foo' defined here 1 | class foo | ^~~
... continue reading