Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide defaulted template parameters in gcc error messages?

Tags:

c++

gcc

templates

Reading through error messages generated by g++ is often a pain because gcc expand names like

std::ostream

in my code into a much longer form like

std::basic_ostream<char, std::char_traits<char> >

in the error messages. Similarly, gcc expands std::string into std::basic_string<char>. I don't see any benefit for such expansions, and it only makes it difficult for me to relate the error messages and the error site.

I was wondering if it is possible tell gcc to disable this expansion behavior and use the shorter names with defaulted template parameters as-is?

There is a related question here which seems to be about not showing the long expanded name at all. I am asking here if it is possible to just show the short name as I used in the code. The answer there also didn't solve the problem.

like image 300
thor Avatar asked Jul 24 '14 08:07

thor


1 Answers

There is no compiler flag to reduce or change the error messages and the related types/templates.

  • gcc suppports coloring since gcc 4.9 with -fdiagnostics-color={auto, always, never}. See the documentation here.

A number of third party tools exist to help you decrypt error messages:

  • GCCFilter for coloring and simplification of error messages (Perl script)
  • ColorGCC in the same vein (Perl script), git is here.
  • STLFilt : A message filter designed for STL-related diagnostics. Note that it is not supported/developed anymore.

Also as a (very good) alternative, the clang compiler is very, very good at diagnosis and error messages.

like image 195
quantdev Avatar answered Sep 21 '22 21:09

quantdev