[cfe-users] how to stop inlining a recursive template function

Larry Evans cppljevans at suddenlink.net
Fri Jan 2 13:02:33 PST 2015


On 12/30/2014 01:03 PM, Larry Evans wrote:
> With:
> 
> 
> http://llvm.org/releases/3.5.0/clang+llvm-3.5.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz
> 
> downloaded on:
> 
> 2014-11-03.2250
> 
> and with the compile command:
> 
> /dwnlds/llvm/3.5/binary/clang+llvm-3.5.0-x86_64-linux-gnu/bin/clang++ -c
> -O0 -g -stdlib=libc++  -std=c++14 -ftemplate-backtrace-limit=0
> -I/home/evansl/prog_dev/boost/sandbox/rw/non_variadic_templates
> -I/home/evansl/prog_dev/boost/boost-modular/TBoost.Conversion
> -I/home/evansl/prog_dev/boost/boost-modular/enums
> -I/home/evansl/prog_dev/clang/libcxx/sandbox/libs/composite_storage/include
> -I/home/evansl/prog_dev/boost/sandbox/rw/sandbox/lje
> -I/home/evansl/prog_dev/boost/boost-releases/ro/boost_1_56_0
> -DTYPE_AT_IMPL=0   -ftemplate-depth=324  texpressions.cpp -MMD -o
> /tmp/build/clangxx3_5_bin/clang/libcxx/sandbox/libs/gram_stk/sandbox/texpressions.o
> 
> 
> I'm getting the error message:
> 
> In file included from texpressions.cpp:1:
> ./texpressions.hpp:1076:36: fatal error: recursive template
> instantiation exceeded maximum depth of 324
>                 boost::trace_scope trace_scope(__FUNCTION__);
>                                    ^
> ./texpressions.hpp:991:19: note: in instantiation of function template
> specialization
>       'texpressions<my_symbols>::definitions<my_attrs,
> composite_storage::type_sequence<texpressions<my_symbols>::def_as<0, 1,
>       texpressions<my_symbols>::expr_prefx<op_assoc<0, 0>,
> 
> texpressions<my_symbols>::expr_prefx<texpressions<my_symbols>::op_symb<0, 0>>,
>       texpressions<my_symbols>::expr_prefx<op_assoc<1, 0>,
> 
> texpressions<my_symbols>::expr_prefx<texpressions<my_symbols>::op_symb<0, 1>>,
> 
> texpressions<my_symbols>::expr_prefx<texpressions<my_symbols>::op_symb<1, 0>>
>>>>>> ::read_fold_from<0,
>       iter_range<my_symbols<0>::syms,
> inp_out_type<my_symbols<0>::syms>::out_type>, def_now_t,
> 
> texpressions<my_symbols>::expr_prefx<texpressions<my_symbols>::op_symb<0, 0>>,
>       texpressions<my_symbols>::expr_prefx<op_assoc<1, 0>,
> 
> texpressions<my_symbols>::expr_prefx<texpressions<my_symbols>::op_symb<0, 1>>,
> 
> texpressions<my_symbols>::expr_prefx<texpressions<my_symbols>::op_symb<1, 0>>
>>> ' requested here
>                   read_fold_from
>                   ^
> 
> 
> Part of the code is:
> 
>             template
>             < typename LiterlStream
>             , vars AnVarble
>             , typename DefNow
>             >
>             bool
>           #define READ_FROM_VAR_NOINLINE
>           #ifdef READ_FROM_VAR_NOINLINE
>             __attribute__((noinline))
>           #endif
>           read_from
>             ( LiterlStream& is
>             , DefNow& def_now_inp
>             , expr_prefx
>               < op_symb
>                 < symb_kinds::varble_kind
>                 , AnVarble
>                 >
>               >const& a_expr
>             )const
>           //#define READ_FROM_VAR_DEF_OUT_CLASS
>           #ifdef READ_FROM_VAR_DEF_OUT_CLASS
>             ;
>           #else
>             {
>                 boost::trace_scope trace_scope(__FUNCTION__);
> 
> std::cout<<"read_from(op_varble<"<<AnVarble<<">)"<<std::endl;
>                 bool
> result=read_def_from(is,def_now_inp,this->get_def<AnVarble>());
>                 return result;
>             }
>           #endif
> 
> The error does not occur when defined(READ_FROM_VAR_DEF_OUT_CLASS).
> I was thinking that maybe unrestrained inlining of the code
> would be causing the problem, but, as seen from the above
> code, even with the __attribute__((noinline)), the error message
> occurs.
> 
> I'd appreciate any suggestions on how to avoid this fatal error
> message about excessive template instantiation.
> 
Further experimentation showed the problem disappeared when
the def_now_inp of *all* the read_*_from overloaded functions
was made an empty class.

The purpose of that parameter is to hold the attributes of the
grammar.  Since the grammar is recursive, I'm guessing that
the attributes would be also.  I'll try to correct that.

Sorry for noise :(

-regards,
Larry






More information about the cfe-users mailing list