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]

Suggestion: Template instantiation debugging


Hello,

I want to suggest a feature which would help me just now a lot,
and I guess everyone else who works with complex templated code
would like it as well (if an equivalent feature already exists and
I just didn't find it, please point me to the relevant documentation):

Add a flag, say -print-instantiations=name, which everytime a
template of that name is instantiated (explicitly or - especially -
implicitly, it prints which template got instantiated, and from
where.

For example:

Say I have

--- foo.cc ---
#include <complex>

template<class T> void foo(T) {}
template<class T> void foo(std::complex<T>) {}

template<class T> void bar(T) {}

int main()
{
  std::complex<double> c;

  foo(5);
  foo(3.14);
  foo(0);
  foo(c);
  bar(5);
}
--- end of foo.cc ---

and would compile with

  g++ foo.cc -print-instantiations=foo

it would print something like

foo.cc:in function main():
foo.cc:3: template<class T> void foo(T)
foo.cc:10: instantiated from here with T=int
foo.cc:3: template<class T> void foo(T)
foo.cc:11: instantiated from here with T=double
foo.cc:4: template<class T> void foo(std::complex<T>)
foo.cc:13: instantiated from here with T=std::complex<double>

Note that the last message points to the specialisation used, not to
the general template. Also note that only instantiations of foo, not
of bar or std::complex are printed.

Since for error messages, gcc already outputs that information
(in the "instantiated from" chain), I think the infrastructure for this
should already be there, so it's probably not too hard to implement for
a gcc expert (however not being a gcc expert, I may be wrong here).

Best regards.


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