Are there tools to transform source code in C++ to the source code in C/C++, but with instantiated (unrolled) templates?
This seems already answered on SO
- Debugging template instantiations
- link 2
- link 3 (with a nice paper too)
- How do you debug heavily templated code in c++?
The Idea/principle from Alexey Frunze to use the disassembled code is quite good, together with the use of simplified templates there is a pretty good chance to understand exactly what it does.
Edit 1 There are a few other possibilities on how to get an understanding of the things which the compiler had done
- Use:
gcc -S -O1 {yourcode.cpp}
to get the assembly and use the toolc++filt
(its a part of binutils to convert the disassembly to C-Code if you feel more comfortable with C-Code - Use:
g++ -fdump-tree-original file.cpp
to get some (pseudo) C++ code - Use the MSVC++ debugger with the breakpoint after the last instantiation and see all types and values which are the parameters of the instantiated template
- Use: GCC XML for generating XML with instantiated templates (FAQ)
- To know how the compiler instantiated and optimized the templates you can use Clang:
-emit-llvm
to get the LLVM IR, and usellvm-dis
to convert it to text - CPP insights is a website of a LLVM based tool to see instantiations
You could work around the problem by placing a deliberate error inside the instantiation or its parameters, then you'd have the compiler (assuming decent versions: gcc 4.8, clang, etc) output something along the lines of: "error with template XXX instantiated with A=int, B=float, ..".