public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/20142] New: implicity assignment with multi-dimensionnal array members
@ 2005-02-22 17:26 bernard dot maudry at topgraphx dot com
  2005-02-23  0:01 ` [Bug c++/20142] " reichelt at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: bernard dot maudry at topgraphx dot com @ 2005-02-22 17:26 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2005-03-09  7:43 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-22 17:26 [Bug c++/20142] New: implicity assignment with multi-dimensionnal array members bernard dot maudry at topgraphx dot com
2005-02-23  0:01 ` [Bug c++/20142] " reichelt at gcc dot gnu dot org
2005-02-23 16:39 ` [Bug c++/20142] [3.3/3.4/4.0 regression] implicit assignment operator with multi-dimensional array is broken reichelt at gcc dot gnu dot org
2005-02-24 15:49 ` reichelt at gcc dot gnu dot org
2005-03-09  6:33 ` [Bug c++/20142] [3.3/3.4/4.0/4.1 " mmitchel at gcc dot gnu dot org
2005-03-09  7:28 ` cvs-commit at gcc dot gnu dot org
2005-03-09  7:32 ` cvs-commit at gcc dot gnu dot org
2005-03-09  7:40 ` cvs-commit at gcc dot gnu dot org
2005-03-09  7:40 ` cvs-commit at gcc dot gnu dot org
2005-03-09  7:41 ` cvs-commit at gcc dot gnu dot org
2005-03-09  7:43 ` [Bug c++/20142] [3.3 " mmitchel at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).