This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [G++] templates not instantiated early enough
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: Chris Lattner <sabre at nondot dot org>
- Cc: gcc at gcc dot gnu dot org
- Date: 04 Jun 2004 05:02:23 +0200
- Subject: Re: [G++] templates not instantiated early enough
- Organization: Integrable Solutions
- References: <Pine.LNX.4.44.0406032109340.27521-100000@nondot.org>
Chris Lattner <sabre@nondot.org> writes:
| I've been tracking down a G++ bug when using my target, and I think that
| the problem needs to be fixed in the generic portion of the C++ front-end
| (which I know very little about).
|
| In particular, consider this testcase:
|
| template<typename Ty>
| struct some_template {};
|
| void foo(some_template<int>);
|
| void bar() {
| foo;
| }
|
| Now it appears that G++ is delaying instantiating the some_template type
| until it actually needs it.
When the declaration of foo is seen, the completeness of the class
type some_template<int> is not needed, only its declaration -- which
the compiler synthetizes.
| In particular, the prototype for foo doesn't
| get emitted to the backend until foo is referenced in "bar".
I don't understand this. When foo is declared, it gets assigned a
type, which is FUNCTION_TYPE (void, some_template<int>).
| This happens
| when the parser sees the reference to foo, and decides that it really
| is referring to the foo function in finish_id_expression.
|
| The problem is that, in this testcase (which is reduced from a
| non-pointless larger testcase), the some_template is never instantiated
| with an int type.
It does not need to. Its completeness is not required. It is only
referenced in a context of parameter-type-list, in a declaration
of foo and no call if made to that function.
| This causes problems for my backend, which needs to
| look at the types for arguments for foo.
If your backend unconditionally assumes that any type referenced in a
function declaration ought to be a complete type, then it contains a bug.
-- Gaby