This is the mail archive of the gcc-bugs@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]

Multiply defined symbol: __copy_dispatch


Hi,

I've posted this about a week ago, but have had no response on it. In
the meantime, I've managed to narrow it down a bit more. There is an
attached uuencoded, gzip'd, tar file containing a small and simple
example.

I've moved up to snapshot 970929 (on a i586-pc-linux-libc1) , but the
problem still exists.

Here is the header file F.h from the example:

----------------- File F.h ------------------------------

//
// Abstract Base Class
//
class Base
{
   public:
      virtual ~Base(void) {}
      virtual void foo(void) = 0;
};

//
// Simple class inheriting from Base
//
class Int : public Base
{
   public:
      virtual ~Int(void) {}
      void foo(void) {}

   private:
      int val;
};

//
// Template class mulitply inheriting from Base and vector
//
template<class T> class MValue : public Base, public vector<T *>
{
   public:

      virtual ~MValue(void) { purge(); }
      void foo(void) {}

   private:

      void purge(void)
      {
         for(MValue<T>::const_iterator it = begin(); it != end(); ++it)
            delete *it;

         erase(begin(), end());
      }
};

typedef MValue<Int> MInt;

-------------- End File F.h
-----------------------------------------------------


The multiple symbols are generated by the call to erase in
MValue<T>::purge. Each file that contains an instance of Mint
(MValue<Int>) will cause the following template structure to be
instantiated from algobase.h:
	
     template class<T>
     struct __copy_dispatch<T *, T *>
     {
         T * operator()(T *first, T *last, T *result) {
            return __copy_t(first, last, result,
                           
__type_traits<T>::has_trivial_assignment_operator());
         }
     };

The mulitple definitions of this template structure cause the linker to
croak.

It appears that the virtual destructor defined by the abstract base
class Base is the key to the problem. If you make the destructor
non-virtual, everything links just fine (although this is not a solution
or work-around since polymorphic behavior is necessary for what I'm
trying to do here). I've tried inheriting MValue from deque and list. It
still fails for the deque, but compiles and links successfully for the
list implementation.

 I've compiled and linked code very similar to this using the MipsPro
7.0.1 compiler (EDG based) on an SGI.

Any help would be greatly appreciated. Thanks in advance,



-- Rick Harding

====================================================================
   ...Be careful whose advice you buy, but be patient with those
   who supply it. Advice is a form of nostalgia.  Dispensing it
   is a way of fishing the past from the disposal, wiping it off,
   painting over the ugly parts and recycling it for more	
   than it's worth...
                                         - K. Vonnegut
====================================================================

test


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