https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118349

--- Comment #4 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #1)
> (In reply to Eric Gallager from comment #0)
> > For example, one could do -Wtemplate-depth=17
> > -ftemplate-depth=1024 to get a warning when the pre-C++11 limit is reached,
> > but only actually fail if the post-C++11 limit is reached.
> 
> Is this just a hypothetical example? It doesn't seem useful to me.
> 
> No useful post-C++11 code will compile with the old limit, so every program
> that uses libstdc++ would warn for -Wtemplate-depth=17

Yes, it's just a hypothetical example, I probably wouldn't actually use such a
low value myself, but rather would determine an appropriate value
experimentally on a project-by-project basis.

(In reply to Jonathan Wakely from comment #2)
> (In reply to Eric Gallager from comment #0)
> > for users who are okay with template usage, but just
> > don't want it to get out of hand.
> 
> What does "get out of hand" mean?  What unwanted consequence would you be
> preventing with this check?
>
> The point of imposing a limit is so that buggy code with infinite recursion
> will (hopefully) stop compiling before the system runs out of memory. So
> it's a check to make accidental infinite recursion fail sooner, rather than
> grind to a halt later.
> 
> I'm not aware of a good use case for "I want some templates, but not too
> much".

It's mostly just a style thing; I find that the deeper template nesting gets in
a project, the harder to understand I find it to be. Also excessive template
depth can lead to code size bloat; I've seen this in some projects that abuse
certain boost templates, for example.

(In reply to Sam James from comment #3)
> People already misunderstand the current option as well (PR65042). It'd just
> get worse.

This actually seems like a perfect example of a case where the user should have
been using -Wtemplate-depth= (if it had existed) instead of -ftemplate-depth=.

Reply via email to