This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
what does -ftemplate-depth-XX mean?
- From: Larry Evans <cppljevans at suddenlink dot net>
- To: gcc-help at gcc dot gnu dot org
- Date: Sun, 24 May 2009 19:32:18 -0500
- Subject: what does -ftemplate-depth-XX mean?
Reading the following:
http://gcc.gnu.org/onlinedocs/gcc-4.4.0/gcc/C_002b_002b-Dialect-Options.html#C_002b_002b-Dialect-Options
and in particular:
-ftemplate-depth-n
Set the maximum instantiation depth for template classes to n. A
limit on the template instantiation depth is needed to detect
endless recursions during template class instantiation. ANSI/ISO
C++ conforming programs must not rely on a maximum depth greater
than 17.
suggested to me that the following code should hit that limit when
compiled with option, -ftemplate-depth-2:
//-{--cons_bench.cpp--
template<class Head, class Tail>
struct cons_hd_tl
{
typedef Head head;
typedef Tail tail;
};
template<typename... Elements>
struct cons_fold
;
template<typename Head, typename... Tail>
struct cons_fold<Head,Tail...>
: cons_hd_tl<Head,cons_fold<Tail...> >
{};
template<>
struct cons_fold<>
{
typedef cons_fold tail;
};
template<int I>
struct ti
{};
typedef cons_fold<ti<1>,ti<2>,ti<3> > cf_3;
//-}--cons_bench.cpp--
I tthought it should fail because cons_fold with five arguments
would call cons_fold recursively 4 or 5 times, which is more than
the 2 specified on the command line.
However, it compiles OK.
What does -ftemplate-depth-XX really mean?
TIA.
-regards,
Larry