This is the mail archive of the gcc-patches@gcc.gnu.org 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]

Re: [Darwin] Patch c++/15428


On May 20, 2004, at 2:04 PM, Jason Merrill wrote:

I still don't see why.  You explained above why this is necessary if
there's a previous extern instantiation, but in that case we already do
explicit instantiations on all targets.

I poked into this a bit more. Oddly enough, what you said was right under my original interpretation, for a reason neither of us noticed. That is: the whole explicitly_instantiate_members stuff in do_type_instantiation is unnecessary. If you set it unconditionally to 0, then, on all targets, what you'll get is still that an explicit instantiation of a class template that has previously been marked extern will result in all of its members getting explicitly instantiated. (But explicit instantiation of a class template that hasn't been marked extern will result in implicit instantiation of its members)

*However*: I think it's still probably a good idea to keep the
explicitly_instantiate_members stuff.  Without it, we're relying
on something that's a bit subtle and that I'm not convinced is
intentional.  It's there for another reason, and I think it gives
this behavior just by accident.  I don't want to count on it.

What's going on: the comments in do_type_instantiation say that
we're doing an implicit instantiation of the members.  So the
first thing we do is call mark_decl_instantiated(tmp, extern_p)
for each member.  Now take a look at mark_decl_instantiated.
If extern_p is true, it calls SET_DECL_EXPLICIT_INSTANTIATION.
(The comments say that it's there to prevent implicit
instantiation of an extern template.)  The explicit bit gets
set when we mark the template as extern.  The next time
through, when we do the real explicit instantiation, nobody has
cleared the extern bit, so we get explicit instantiations of
all the members.

Like I said, I think this is probably an accident.  I think the
extern bit was set just to prevent implicit instantiations, and
nobody thought about what it implied for the case of an extern
template that's later instantiated explicitly.

I'm inclined to keep the explicitly_instantiate_members code,
because it makes it clear what's going on.  But I could be
persuaded to get rid of it, and just put in a comment documenting
what's going on and asserting that it's intentional.

Thoughts?

--Matt


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