As the title says, is there any compiler logging settings which provides the max instantation deph reached by the compiler during compilation?
If the compilation exceds the max template deph (Which GCC's default value is 900 in C++11 mode), compilation fails. But what I need is to get the maximum template instantation depth which the compiler has reached during a successfull compilation.
Templates are instantiated in the process of converting each translated translation unit into an instantiation unit. A translation unit is essentially a source file. A translated translation unit (try to say that three times fast) is the output from compilation without templates instantiated.
When a function template is first called for each type, the compiler creates an instantiation. Each instantiation is a version of the templated function specialized for the type. This instantiation will be called every time the function is used for the type.
All the template parameters are fixed+known at compile-time. If there are compiler errors due to template instantiation, they must be caught at compile-time!
In order for any code to appear, a template must be instantiated: the template arguments must be provided so that the compiler can generate an actual class (or function, from a function template).
g++
does have such an option, but it isn't enabled by default on kubuntu, for example.
The following is part of gcc/cp/tree.c
from gcc-4.8.1
(and is therefore licensed under the GPL):
void
cxx_print_statistics (void)
{
print_search_statistics ();
print_class_statistics ();
print_template_statistics ();
if (GATHER_STATISTICS)
fprintf (stderr, "maximum template instantiation depth reached: %d\n",
depth_reached);
}
You can get those statistics when adding -fdump-statistics -fstats
to your command line, but GATHER_STATISTICS
has to be enabled at the time you compile gcc
, so you will probably have to rebuild gcc
in order to get the functionality you are looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With