Better Template Error Messages
Contents |
DevJolt Awards Channels▼ CloudMobileParallel.NETJVM LanguagesC/C++ToolsDesignTestingWeb DevJolt Awards Tweet Permalink Better Template Error Messages By Andrei Alexandrescu, March 01, 1999 We take for granted that debugging templates is a nightmare, but maybe that build template error message doesn't have to be true forever. March 1999/Better Template Error
Build Template Error Message Lexmark Uninstall
Messages When templates were first incorporated into C++, perhaps few people realized how much power they best error messages would bring to the language. If we surveyed the last five years' worth of CUJ articles, we would turn up many more applications for templates than for
C++ Template Error Messages
polymorphism, one of the three pillars of object-oriented programming. But templates exact a price in their use, and it is one that causes many programmers to avoid using them altogether. Template code is hard to debug. In fact, it is so hard that one of our readers felt obliged to speak out about it. the grand c++ error explosion competition The article that follows is Andrei Alexandrescu's call for compiler vendors to improve the template diagnostics produced by their compilers. We've given three compiler experts the opportunity to respond to Alexandrescu's proposal: Steve Clamage, of Sun Microsystems John Spicer, of Edison Design Group, and Jonathan Caves, of Microsoft Corporation All three were gracious enough to offer their comments. We present their edited responses immediately after this article. We would not claim that the solutions proposed here are the only possible ones, nor even the best. But it is our hope that this article will stir up discussion among compiler users and vendors. Templates are a powerful tool for writing safe, efficient, and reusable code. We think it's a shame that such a useful tool is marred by cryptic error messages. If you feel the same way, let your compiler vendors know. C++ is a great language. Let's help it live up to its full potential. mb Andrei Ale
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers
Longest C++ Program
or posting ads with us Programmers Questions Tags Users Badges Unanswered Ask Question _ Programmers Stack
Stlfilt
Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute: c++ error message Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Why are C++ template error messages so horrific? up vote 14 down vote favorite 4 http://www.drdobbs.com/better-template-error-messages/184403616 C++ templates are notorious for generating long, unreadable error messages. I have a general idea of why template error messages in C++ are so bad. Essentially, the problem is that the error isn't triggered until the compiler encounters syntax that is not supported by a certain type in a template. For example: template
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and http://stackoverflow.com/questions/47980/deciphering-c-template-error-messages policies of this site About Us Learn more about Stack Overflow the http://people.cs.uchicago.edu/~jacobm/pubs/templates.html company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only error message takes a minute: Sign up Deciphering C++ template error messages up vote 22 down vote favorite 8 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 template error message these errors? EDIT: I'm using both gcc and MSVC. They both seem to be pretty terrible. c++ templates compiler-errors share|improve this question edited Sep 24 '08 at 11:16 Motti 51.9k27130205 asked Sep 7 '08 at 0:39 Jason Baker 79.3k81290464 add a comment| 5 Answers 5 active oldest votes up vote 14 down vote accepted You can try the following tool to make things more sane: http://www.bdsoft.com/tools/stlfilt.html share|improve this answer answered Sep 7 '08 at 0:42 nsanders 6,92622843 add a comment| up vote 7 down vote 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?). share|improve this answer answered Sep 7 '08 at 2:32 Bernard 16.2k124364 add a comment| up vote 3 down vote 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
the version posted at Kuro5hin.org except that I've reformatted all the code samples to be indented properly.] If you've read The Hitchhiker's Guide to the Galaxy and its sequels, you probably remember the Vogons, the incredibly ugly, disgusting, and bad-tempered aliens charged with destroying Earth to clear the path for an intergalactic highway. The Vogons' brains, it turns out, were "originally a badly deformed, misplaced and dyspeptic liver" -- and that explains their demeanor. In this article, I'll explain why I think C++ has a badly deformed, misplaced and dyspeptic liver of its own: its template system. Before I make my case, I want to make sure my position on templates is clear. For the record: if you're going to program in C++, templates are unquestionably useful, and I hope you won't mistake me for one of those people who say that templates aren't necessary and we should all be using inheritance instead or some gobbledygook like that -- I'm not. If you want to program in C++ there are lots of times when templates are absolutely the best option the language gives you for writing generic, reusable code. On the other hand, just because templates are the best C++ has to offer doesn't mean they're good. It turns out that all the problems templates solve were already solved better, before templates were ever introduced, by other languages. In fact, the kludgey way templates work precludes C++ programmers from a lot of the good stuff that nicer solutions have. What are templates, and why should I care? Templates are a widely-used C++ feature that have simple behavior with complicated consequences. What they do is allow you to mark particular code fragments that might otherwise look like functions, methods or classes as being, in fact, templates for those functions, methods or classes that have holes in them where later on, different people can place certain interesting constants, like type names or numbers. For example, the function int myCleverFuncti