[Bug c++/20142] New: implicity assignment with multi-dimensionnal array members

bernard dot maudry at topgraphx dot com gcc-bugzilla@gcc.gnu.org
Tue Feb 22 17:26:00 GMT 2005


Problem:
If a struct has a member which is a multi-dimensionnal array of class with an
explicit assignment operator, a trivial implicit operator is generated instead
of a non trivial one.

Code:
//
#include <stdio.h>

class Manager
{
  public:
    Manager (void);
    Manager (const Manager &);
    ~Manager (void);
    Manager &operator= (const Manager&);
  private:
    /// The underlying data
    int ptr_;
    static int Count ;
};

typedef Manager ArrayString[2];
typedef ArrayString ArrayOfArrayString[2];
struct  DataItem
{
  ArrayOfArrayString field;
};

int Manager::Count = 0 ;
Manager::Manager (void) :  ptr_ (0) { }
Manager::Manager (const Manager &rhs) : ptr_ (rhs.ptr_ + 100) {}
Manager::~Manager (void) { printf ("Destructor: Ptr %d\n", ptr_) ; }
Manager& Manager::operator= (const Manager &rhs) {
  ptr_ = rhs.ptr_ + 1 ;
  Count++ ;
  printf ("Assignment %d\n", Count) ;
  return *this;
}

void Check (const DataItem & item)
{
  DataItem item_1 ;
  DataItem item_2 ;

  item_1 = item ;
  item_2 = item ;
}

int main (int argc, char ** argv)
{
  DataItem item ;

  Check (item) ;
}

Build line :
g++ -O0 -g -o assign assign.cpp

Output:
Destructor: Ptr 0
Destructor: Ptr 0
Destructor: Ptr 0
Destructor: Ptr 0
Destructor: Ptr 0
Destructor: Ptr 0
Destructor: Ptr 0
Destructor: Ptr 0
Destructor: Ptr 0
Destructor: Ptr 0
Destructor: Ptr 0
Destructor: Ptr 0

Assigment operator of class Manager was never called.

g++ -v
Reading specs from /opt/gcc332/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/specs
Configured with: ./configure --prefix=/opt/gcc332 --enable-threads=posix
--enable-languages=c,c++
Thread model: posix
gcc version 3.3.2

and
Reading specs from /usr/lib/gcc/i586-mandrake-linux-gnu/3.4.1/specs
Configured with: ../configure --prefix=/usr --libdir=/usr/lib
--with-slibdir=/lib --mandir=/usr/share/man --infodir=/usr/share/info
--enable-shared --enable-threads=posix --disable-checking --enable-long-long
--enable-__cxa_atexit --enable-clocale=gnu --disable-libunwind-exceptions
--enable-languages=c,c++,ada,f77,objc,java --host=i586-mandrake-linux-gnu
--with-system-zlib
Thread model: posix
gcc version 3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk)

-- 
           Summary: implicity assignment with multi-dimensionnal array
                    members
           Product: gcc
           Version: 3.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bernard dot maudry at topgraphx dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20142



More information about the Gcc-bugs mailing list