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