Skip to content

Almost reached the limit of template instantiation depth #639

@Genomorf

Description

@Genomorf

Hello. I have big transition table with a lot of states, events and actions. I know that you use some TMP to handle dependencies. Something like merge or join all deps into type_list and do aux::unique. It seems that i almost reached the limit of default (900) template instantiation depth during that operation.

During investigation of the issue, i used "-ftemplate-depth=500" and got compilation fail on instantiation of sm::deps_t type.

Result is an aux::type_list with 829 template parameters. Unique params are only 3. Example:
aux::type_list<dep_type1&, dep_type2&, logger_dep&, ... + 826 repeated params>

Num of dep_type1 params = 414.
Num of dep_type2 params = 414.
Num of logger_dep params = 1.

I can't just increase -ftemplate-depth to a larger number. gcc docs warns about it: https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/C_002b_002b-Dialect-Options.html

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 (changed to 1024 in C++11). The default value is 900, as the compiler can run out of stack space before hitting 1024 in some situations.

Could you please clarify:

  1. Is it expected and designed behavior to have so many repeated template parameters?
  2. How can i reduce number of template parameters during instantiation of sm class? Let's say, i don't want to split the fsm into several smaller fsms.
  3. Finally, do you recommend to increase -ftemplate-depth ignoring note of warning from gcc docs?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions