public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/18975] New: Copying objects with mutable non-static data members
@ 2004-12-14  7:19 wolfgang dot roehrl at de dot gi-de dot com
  2004-12-14 13:26 ` [Bug c++/18975] " pinskia at gcc dot gnu dot org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: wolfgang dot roehrl at de dot gi-de dot com @ 2004-12-14  7:19 UTC (permalink / raw)
  To: gcc-bugs

Dear all,

I would like to post a bug report for the GNU C/C++ compiler 3.3-e500.

We use the compiler to generate code for a PowerPC processor.

Used invokation line for the GNU C++ compiler:

ccppc -c -x c++ -ansi -Wall -Werror -mcpu=8540 -fverbose-asm -mbig
      -fmerge-templates -mmultiple -mno-string -mstrict-align -O3
      -fno-exceptions -fno-rtti -fno-builtin-printf
      -I<different include paths>
      -D<differen #define's>
      K.CPP -oK.O


// [ start of example program

struct PTR
{
    PTR ();
    PTR (PTR&);
    PTR& operator= (PTR&);

private:
    PTR (const PTR&);                             // <--- line 8
    PTR& operator= (const PTR&);                  // <--- line 9

    void* ptr;
};


struct XYZ
{
    XYZ (PTR& p) : ptr(p) {}

//  XYZ (const XYZ& src) : ptr(src.ptr) {}        // <--- line 19
//  XYZ& operator= (const XYZ& src) { ptr = src.ptr; return *this; }

    mutable PTR ptr;
};


XYZ f1 ();


XYZ f2 (void) { return f1(); }                    // <--- line 29
void f3 (XYZ& dst, const XYZ& src) { dst = src; } // <--- line 30

// end of example program ]


The compiler gives the following error messages:

z.CPP: In copy constructor `XYZ::XYZ(const XYZ&)':
z.CPP:8: error: `PTR::PTR(const PTR&)' is private
z.CPP:29: error: within this context
z.CPP: In member function `XYZ& XYZ::operator=(const XYZ&)':
z.CPP:9: error: `PTR& PTR::operator=(const PTR&)' is private
z.CPP:30: error: within this context



I think that the compiler should implicitly declare and define a copy
constructor and a copy assignment operator for XYZ as follows:
- The copy constructor should be declared as "XYZ::XYZ (const XYZ&);" since PTR
  has a (private) copy constructor whose first parameter is "const PTR&". (Cf.
  12.8/5; it doesn't matter if the copy constructor is accessible.)
- The copy assignment operator should be declared as "XYZ& XYZ::operator=
  (const XYZ&);" since PTR has a (private) copy assignment operator whose first
  parameter is "const PTR&". (Cf. 12.8/10; it doesn't matter if the copy
  assignment operator is accessible.)
- The implicitly defined copy constructor should use the copy constructor of
  PTR (12.8/8). Since the member ptr of XYZ is MUTABLE the (public) copy
  constructor PTR::PTR (PTR&) should be called after overload resolution:
  "PTR::PTR (PTR&)" is a better match than "PTR::PTR (const PTR&)".
- The same reasoning is true of the implicitly defined copy assignment
  operator.

By the way I don't get an error if I define the copy constructor and the copy
assignment operator explicitly in XYZ: please un-comment line 19 und 20 in the
code fragment above.


Kind regards
W. Roehrl

-- 
           Summary: Copying objects with mutable non-static data members
           Product: gcc
           Version: 3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: wolfgang dot roehrl at de dot gi-de dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: sparc-sun-solaris2.5.1
  GCC host triplet: i386-pc-mingw32
GCC target triplet: powerpc-wrs-vxworks


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


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

end of thread, other threads:[~2004-12-21 17:29 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-14  7:19 [Bug c++/18975] New: Copying objects with mutable non-static data members wolfgang dot roehrl at de dot gi-de dot com
2004-12-14 13:26 ` [Bug c++/18975] " pinskia at gcc dot gnu dot org
2004-12-14 13:41 ` giovannibajo at libero dot it
2004-12-14 13:58 ` nathan at gcc dot gnu dot org
2004-12-14 14:20 ` wolfgang dot roehrl at de dot gi-de dot com
2004-12-14 16:55 ` nathan at gcc dot gnu dot org
2004-12-15 14:45 ` nathan at gcc dot gnu dot org
2004-12-17 13:20 ` giovannibajo at libero dot it
2004-12-17 13:44 ` nathan at gcc dot gnu dot org
2004-12-17 16:11 ` nathan at gcc dot gnu dot org
2004-12-17 16:19 ` cvs-commit at gcc dot gnu dot org
2004-12-17 16:34 ` bangerth at dealii dot org
2004-12-17 17:21 ` [Bug c++/18975] [4.0 regression] " steven at gcc dot gnu dot org
2004-12-17 17:23 ` pinskia at gcc dot gnu dot org
2004-12-21 17:27 ` nathan at gcc dot gnu dot org
2004-12-21 17:29 ` cvs-commit 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).