Boost logo

Boost :

From: Markus Schöpflin (markus.schoepflin_at_[hidden])
Date: 2005-07-01 05:13:43


Christoph Ludwig wrote:

> On Wed, Jun 29, 2005 at 02:52:12PM +0200, Markus Schöpflin wrote:

>> The problem is that the compiler _needs_ the explicit instantiation in
>> order not to end up with multiple defitions of a static variable used
>> in the class. And where should that instantiation be written, if not
>> in the header?

> I don't know the peculiarities of the Tru64/CXX compiler. If it does not
> care about multiple explicit instantiations (or even requires them for
> some reason), then it may make sense to ignore the standard *on this
> particular platform*. The explicit instantiation should be guarded by
> #ifdefs that filter out all other platforms, though.

No reply from the vendor on this yet, but I did some more testing.
Basically, I tested with the following header file included into two
different TUs and then linked together into a single application. This
should mirror the situation in question close enough, I hope.

---%<---
#include <iostream>

template <class T>
struct foo_base
{
   static void bar()
   {
     static T t = T();
     std::cout << "t=" << t << '\n';
     ++t;
   }
};

template void foo_base<int>::bar();

struct foo : public foo_base<int> { };
--->%---

Each TU included a call to foo::bar() and only when the explicit
instantiation of foo_base::bar() was present, the program worked as
expected in all instantiation modes, when compiled with cxx (and g++) on Tru64.

I had a look at the generated object files and indeed there are definitions
for the static variable t in each object file, but they have so called
common linkage, which means that only one symbol is finally chosen.

So I think it will be ok to add the change when the instantiation is
wrapped in appropriate #ifdefs. What do you think, John?

Markus


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk