正如标题所说,是否有任何编译器日志记录设置可以提供编译器在编译期间达到的最大实例深度?
如果编译超过了最大模板深度(C++11模式下GCC的默认值为900),编译失败。但我需要的是获得编译器在成功编译期间达到的最大模板实例化深度。
g++
确实有这样的选项,但例如在 kubuntu 上默认情况下没有启用它。
以下是gcc/cp/tree.c
from的一部分gcc-4.8.1
(因此在 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
构建才能获得所需的功能。