Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simpler c++ template compile error output

When working with templates in C++ any errors cause the compiler to emit a lot of output. In most cases when I am working on something most of that information is noise and I have to scroll around looking for the info I am interested in, for example:

  • Every template candidate is listed. I rarely have use for this long list and it just clutters the output.
  • Aliases for template specializations are expanded, e.g. std::string is written as std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, or expanded typedefs / alias declarations. I would prefer to have them unexpanded for easier reading.

Is it possible in either g++ or clang to reduce any of this for shorter/simpler output?

Obviously the information can be important, but then I would prefer to compile again with more verbosity and keep it short and simple by default.

like image 829
Zitrax Avatar asked Dec 08 '18 22:12

Zitrax


Video Answer


1 Answers

Unfortunately there's no way to deal with this currently. C++20 solves this problem by introducing concepts, where templates can have abstract definitions that are restricted with everything except for their binary layout. Violating these definitions will provide simple errors.

Currently, I dig into these lines and I got used to it. I'm currently dealing with a program with 5 template parameters at places. It's all about getting used to it and training your eyes to parse the content.

However, if you're really stuck, one solution I may suggest is that you copy all the relevant error output to some editor, and do a find-and-replace to simplify individual expressions, making them smaller and smaller with every replace until it becomes readable for you. Good skills in regex may help as well. In Notepad++ (or Notepadqq on linux), you can find regular expressions and use capture groups in the replacement with \1 for first capture group, \2 for second, etc.

So, bottom line: Until C++20, there's no clean solution for this except what you invent yourself.

like image 177
The Quantum Physicist Avatar answered Sep 23 '22 16:09

The Quantum Physicist