How to debug template arguments at compile time?

I have a piece of code that pretty much boils down to:

template<class T> struct MyStruct; // No definition by default template<class T> struct MyStruct<T *> { ... }; // Specialization for pointers 

Now somewhere in my code, I get an instance of MyStruct<T> which turns out to be undefined (no C ++ 0x / 011, no Boost ... nothing unusual, just C ++ 03)

 error C2027: use of undefined type 'MyStruct<T>' 

The problem is that I have no idea where , because the code that executes the instance is itself a template and is called from many places with different arguments.

Is there a way to somehow figure out what T at compile time to better understand error messages?

(Sorry, I forgot to mention: Visual Studio 2008.)

+4
source share
2 answers

I believe that you are using MSVC ++, if so, then look at the output window, it may contain more information, especially the line number along with the file name. Once you find out the file number and number, you can start from there.

The output window usually prints everything, how and with which template template (s) the template is instantiated. All step by step. These messages are very helpful when debugging.

As you understand, inclusion / WL prints more detailed messages in an output window.

+4
source

I know that you said no to C ++ 11, but you might think, since C ++ 03 code is backward compatible with all C ++ 11 compatible compilers to use the static_assert function for C ++ 11 to debug your code ... if you must complete the final compilation using the C ++ 03 compiler, you can always create #define and use the #ifdef and #endif preprocessor macros to ensure that static_assert does not cause problems in earlier compilers that do not support features C ++ 11.

See the MSDN docs here for more details.

0
source

All Articles