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 Thu, 20 May 2004 14:00:32 -0700, Matt Austern <austern@apple.com> wrote:

> 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.

Yes.

> On most targets we deliberately decided to do the latter.

Yes.

> On Darwin we need to do the former.

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.

Jason


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