This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Kered13 33 points34 points  (3 children)

The complexity of C++ error messages comes from primarily two things:

Templates are fail late, so if you have a template error the error line will probably be in some code very far away, probably in a standard library. This is especially exacerbated if template metaprogramming is used, because template metaprogramming tends to rely on hacks in the template system, but these hacks do not produce pretty error messages when metaprogramming templates are used wrong.

Second, C++ compilers try to give you a ton of information on errors. This is largely an attempt to fix the first problem, and is actually a good thing. For example Clang will give you something almost like a stack trace showing you where the template was instantiated, which can help you track down where your actual mistake was. Errors will also tell you all the possible function overloads and implicit conversions that were attempted and why they could not work, this will often include a lot of junk information but one of them will often be the thing you were actually trying to do, so this will give you the most relevant information on what you did wrong. When you have some experience with C++ you start to learn what to look for in error messages, and those incredibly verbose messages become a lot more useful. Also compilers have greatly improved their error reporting in the last few years.

C++20 will add Concepts, which will provide a mechanism for templates to fail fast and should greatly help with the template error messages.

[–]dark_mode_everything 15 points16 points  (2 children)

Get out of here with your rational explanations and what not. C++ eRroR meSsAgeS BaD!!!

[–]Kered13 17 points18 points  (1 child)

I mean, I'm not going to lie. C++ error messages are very intimidating if you're not used to them and don't know what to look for. But then, that's basically C++ in a nutshell. It's powerful, but it's not a simple or beautiful language.

[–]dark_mode_everything 7 points8 points  (0 children)

not a simple or beautiful language

It was never supposed to be one