what does -ftemplate-depth-XX mean?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux