正如标题所说,是否有任何编译器日志设置可以提供编译器在编译期间达到的最大实例深度?
如果编译超过max template deph(GCC在C++11模式下默认值为900),则编译失败。但我需要的是获得编译器在成功编译期间达到的最大模板实例化深度。
最佳答案
g++
确实有这样的选项,但例如在 kubuntu 上默认情况下不启用它。
以下是 gcc-4.8.1
的 gcc/cp/tree.c
的一部分(因此根据 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);
}
将 -fdump-statistics -fstats
添加到命令行时,您可以获得这些统计信息,但是 GATHER_STATISTICS
必须在编译 gcc
时,您可能必须重建 gcc
才能获得您正在寻找的功能。
关于c++ - 获取编译期间使用的最大模板实例化深度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18812169/