public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/5050: template instantiation depth
@ 2003-01-22 19:16 Wolfgang Bangerth
0 siblings, 0 replies; only message in thread
From: Wolfgang Bangerth @ 2003-01-22 19:16 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c++/5050; it has been noted by GNATS.
From: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
To: gcc-bugs@gcc.gnu.org, <gcc-gnats@gcc.gnu.org>
Cc: georg.wild@gmx.de, <neroden@twcny.rr.com>
Subject: Re: c++/5050: template instantiation depth
Date: Wed, 22 Jan 2003 13:11:12 -0600 (CST)
This report is about the following code (extracted by Nathanael):
--------------
struct ostream {
template<class T> ostream& foo( const T & )
{ return *this; }
};
void foo() {
ostream os;
(os.foo(1)).foo(2);
}
-----------------
It compiles fine without optimization and -ftemplate-depth-1, since
ostream::foo really needs to be instantiated only once. It fails with
optimization -O saying that the maximal instantiation depth is exceeded.
I think that this is actually a bug in the inliner, since the bug can be
made to go away when one specifies "-O -fno-inline". My naive
understanding is that the inliner just copies the body of the foo function
into the calling place, so the function is not instantiated, although the
instantiation counter is bumped up by one. When we get to the second call
of foo(), we check that the function has not been instantiated, so needs
to be instantiated now, but then the instantiation counter is already at
1, and we fail.
The solution would probably be to not increase the template instantiation
depth counter when a function is inlined, rather than instantiated.
Regards
Wolfgang
-------------------------------------------------------------------------
Wolfgang Bangerth email: bangerth@ticam.utexas.edu
www: http://www.ticam.utexas.edu/~bangerth/
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2003-01-22 19:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-22 19:16 c++/5050: template instantiation depth Wolfgang Bangerth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).