This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[G++] templates not instantiated early enough

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() {

Now it appears that G++ is delaying instantiating the some_template type
until it actually needs it.  In particular, the prototype for foo doesn't
get emitted to the backend until foo is referenced in "bar".  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.  This causes problems for my backend, which needs to
look at the types for arguments for foo.  Currently, since the template is
never being instantiated, the TYPE_SIZE and other fields are null.  The
target that I'm working on specifically needs types laid out for function
prototypes that take an aggregate value by value (as in this case).
Pointers to templates can be lazily instantiated as needed.

So my questions are as follows:
 1. Is it legal in C++ to instantiate the template at the point where foo
    is referenced?  I assume so, because there is already a prototype that
    has referenced it, but I don't know much about the G++ frontend.
 2. If so, where is the correct place to do this?  I am guessing that it
    eventually boils down to calling instantiate_class_template on the
    argument type, but where should this go?  I would guess it probably
    goes in finish_id_expression, but again, I don't know much about this
    stuff. :)

Thanks in advance for any help.  I suspect that this is pretty simple for
someone who knows stuff about the C++ frontend.

Have fun at the summit, I wish I could be there.  :)



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]