Deciphering C++ template error messages

10,036

Solution 1

You can try the following tool to make things more sane:

http://www.bdsoft.com/tools/stlfilt.html

Solution 2

I sure as hell can't. Small errors explode into pages and pages of unreadable junk. Usually early in the morning, before coffee. :(

My only advice is to take a deep breath, start at the top and try and parse the important pieces of information. (I know, easier said than done, right?).

Solution 3

As @nsanders said STLFilt is a good solution. A home grown STLFilt (when you don't want to go to the trouble of installing Perl) is to copy the error message in an editor and start replacing parts of the error until it becomes (more) manageable.

e.g.

s/std::basic_string<char,std::char_traits<char>,std::allocator<char>>/string/g 

In less geeky terms this means:

Replace:

std::basic_string<char,std::char_traits<char>,std::allocator<char>>

With:

string

Solution 4

Some compilers give better messages than others. What compiler are you using? Having said that, they are all pretty bad. C++0X will fix most of this problem (see concepts), but the standard won't be released until 2009, and broad support will probably be even later than that :-(

Solution 5

At least in Visual Studio, there is more information given in the Output Build window rather than the Error List. I've had a template error in the Error List state, "Cannot convert Foo<int> to Foo<int>". There were some lines following the actual error in the Output window that helped me to decipher what the actual problem was.

Share:
10,036
Jason Baker
Author by

Jason Baker

I'm a developer on Google's Cloud Console.

Updated on June 18, 2022

Comments

  • Jason Baker
    Jason Baker almost 2 years

    I'm really beginning to understand what people mean when they say that C++'s error messages are pretty terrible in regards to templates. I've seen horrendously long errors for things as simple as a function not matching its prototype.

    Are there any tricks to deciphering these errors?

    EDIT: I'm using both gcc and MSVC. They both seem to be pretty terrible.

  • artless noise
    artless noise about 11 years
    -1 They are still undecipherable; maybe not as undecipherable as before, but still horrid!
  • Translunar
    Translunar over 10 years
    Yeah, I'm struggling with one right now. They're just so hard to parse visually!
  • Admin
    Admin about 10 years
    Concepts didn't make it into C++11.
  • breakpoint
    breakpoint almost 7 years
    This is more useful than it sounds. Don't feel embarrassed about the information-overload limits of the human brain-- and there's less variation between people there then they like to admit. We can all match about the same number of patterns at once-- the trick is to gradually learn to match larger patterns.
  • dashesy
    dashesy almost 7 years
    8 years later and concepts are now in C++17. How are they going to help in deciphering the template errors?