8

正如标题所说,是否有任何编译器日志记录设置可以提供编译器在编译期间达到的最大实例深度?

如果编译超过了最大模板深度(C++11模式下GCC的默认值为900),编译失败。但我需要的是获得编译器在成功编译期间达到的最大模板实例化深度。

4

1 回答 1

7

g++确实有这样的选项,但例如在 kubuntu 上默认情况下没有启用它。

以下是gcc/cp/tree.cfrom的一部分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构建才能获得所需的功能。

于 2013-09-15T14:59:57.357 回答