This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Tracing C++ template instantiations


When I'm working on complicated template code and debugging a mixture
of bugs in my templates and ICEs in g++ caused by my buggy templates I
sometimes wish I could see a dump of all the templates that the
compiler is instantiating, so I can see at which point in a
deeply-nested instantiation things don't happen the way I expected
them to.  With variadic templates in particular it's sometimes hard to
visualize what's happening to your code.

Someone else asked for this the other day on gcc-help
(http://gcc.gnu.org/ml/gcc-help/2011-06/msg00193.html) so I thought
I'd take a look at implementing it. It turns out that or class
templates all that's needed is something like:
 verbatim ("instantiating class template %qT", type)
in instantiate_class_template_1 in gcc/cp/pt.c
Presumably it wouldn't be much harder to do the same for function templates.

Is there something that does this already that I've missed?  If I were
to add a switch like -ftrace-template-instantiation to control this,
is there any chance of getting it accepted?

It might be useful if the trace said something like:
  attempting to instantiate foo<bar>...
    attempting to instantiate foo<bar>::baz<int> ...
    successfully instantiated foo<bar>::baz<int>
  failed to instantiate foo<bar>
with nesting to see which instantiations depend on others and to see
which pass/fail, but I've already found it useful just to see a list
of instantiations, in order to verify whether some refactoring reduces
the number of instantiations.

Would anyone else find this useful, or should I just keep it in my own
source tree for my own use?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]