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 11:57 AM, Jason Merrill wrote:

On Thu, 20 May 2004 11:38:11 -0700, Matt Austern <austern@apple.com> wrote:

       explicitly_instantiate_members =
!       !TARGET_WEAK_NOT_IN_ARCHIVE_TOC
         && previous_instantiation_extern_p && ! extern_p
         && ! TYPE_FOR_JAVA (t);

OK, so here' s a specific code example. Suppose we have a header file x.h
with the following declarations:
template <typename T> struct X { void foo(); };
template <typename T> void X<T>::foo() { };
extern template struct X<int>;


Now we include that header file into two source files, a.cc and b.cc. In
a.cc we use X<int>::foo(), but we don't have an explicit instantiation.
In b.cc we do have an explicit instantiation. a.o will have an
unresolved reference to _ZN1XIiE3fooEv, which is expected to be defined
elsewhere. b.o will have a definition. The point is that we need to
make sure that the definition of _ZN1XIiE3fooEv in b.o isn't weak. So we
do two things. First, we do explicit instantiations, not implicit, for
member functions of explicitly instantiated class templates.

My issue is twofold:


1) It seems to me that the above code would accomplish this for your
testcase without checking TARGET_WEAK_IN_ARCHIVE_TOC; since the previous
instantiation was "extern", this one will be explicit.

I believe the check for the macro is necessary. We know that the instantiation of this class template is explicit, but we still have to decide whether that means that the members should be instantiated explicitly or implicitly. On most targets we deliberately decided to do the latter. On Darwin we need to do the former. The only way we could give up checking for this macro is if we decided that explicit instantiation of a class template should imply explicit instantiation of its member on all targets. I didn't want to slip in a change to a deliberate decision in the guise of fixing one target.



2) It looks like the test of TARGET_WEAK_IN_ARCHIVE_TOC is backwards, and
will force the member instantiations to always be *implicit* on Darwin.

You're right. This looks like a goof from when I changed the sense of the macro. Thanks for catching it! I'll submit a new patch with the fix.


--Matt


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