Chapter 8. Diagnostics
Because C++ metaprograms are executed during compilation, debugging presents special challenges. There's no debugger that allows us to step through metaprogram execution, set breakpoints, examine data, and so onthat sort of debugging would require interactive inspection of the compiler's internal state. All we can really do is wait for the process to fail and then decipher the error messages it dumps on the screen. C++ template diagnostics are a common source of frustration because they often have no obvious relationship to the cause of the error and present a great deal more information than is useful. In this chapter we'll discuss how to understand the sort of errors metaprogrammers typically encounter, and even how to bend these diagnostics to our own nefarious purposes.
The C++ standard leaves the specifics of error reporting entirely up to the compiler implementor, so we'll be discussing the behaviors of several different compilers, often in critical terms. Because your compiler's error messages are all the help you're going to get, your choice of tools can have a huge impact on your ability to debug metaprograms. If you're building libraries, your clients' choice of tools will affect their perception of your codeand the time you spend answering questionswhen mistakes are made. Therefore, we suggest you pay close attention even when we're discussing a compiler you don't normally use: You may discover that you'd like to have it in your kit, or that you'll want to do something special to support clients who may use it. Likewise, if it seems as though we're attacking your favorite tool, we hope you won't be offended!
|