This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/18975] Copying objects with mutable non-static data members
- From: "nathan at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 15 Dec 2004 14:44:44 -0000
- Subject: [Bug c++/18975] Copying objects with mutable non-static data members
- References: <20041214071926.18975.wolfgang.roehrl@de.gi-de.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From nathan at gcc dot gnu dot org 2004-12-15 14:44 -------
I am dubious about my own analysis of this. Wolfgang sent me more detailed
comparison between g++ and comeau
Hi Nathan,
I try to explain what I meant with my last comment. I have three variations
of my code example and I tried to compile them with GNU 3.3 and Comeau
online.
===========================================================================
The following code is accepted by GNU as well as by Comeau:
struct PTR
{
PTR ();
PTR (PTR&);
PTR& operator= (PTR&);
private:
PTR (const PTR&);
PTR& operator= (const PTR&);
void* ptr;
};
struct XYZ
{
XYZ (PTR& p) : ptr(p) {}
XYZ (const XYZ& src) : ptr(src.ptr) {}
XYZ& operator= (const XYZ& src) { ptr = src.ptr; return *this; }
mutable PTR ptr;
};
XYZ f1 ();
XYZ f2 (void) { return f1(); }
void f3 (XYZ& dst, const XYZ& src) { dst = src; }
===========================================================================
The following code is rejected by GNU (GNU flags line 28) and accepted by
Comeau:
struct PTR
{
PTR ();
PTR (PTR&);
PTR& operator= (PTR&);
private:
PTR (const PTR&);
PTR& operator= (const PTR&);
void* ptr;
};
struct XYZ
{
XYZ (PTR& p) : ptr(p) {}
XYZ& operator= (const XYZ& src) { ptr = src.ptr; return *this; }
mutable PTR ptr;
};
XYZ f1 ();
XYZ f2 (void) { return f1(); } // <--- this is line 28
void f3 (XYZ& dst, const XYZ& src) { dst = src; }
===========================================================================
The following code is rejected by both GNU (GNU flags line 26 and 27) and
Comeau (Comeau flags line 27):
struct PTR
{
PTR ();
PTR (PTR&);
PTR& operator= (PTR&);
private:
PTR (const PTR&);
PTR& operator= (const PTR&);
void* ptr;
};
struct XYZ
{
XYZ (PTR& p) : ptr(p) {}
mutable PTR ptr;
};
XYZ f1 ();
XYZ f2 (void) { return f1(); } // <--- this is line
26
void f3 (XYZ& dst, const XYZ& src) { dst = src; } // <--- this is line
27
===========================================================================
Two remarks:
- In my first code fragment I have defined an explicit copy constructor and
an explicit copy assigment operator for class XYZ, in my third code
fragment
there is neither an explicit copy constructor nor an explicit copy
assigment
operator for class XYZ.
Why is the first code legal and the third code illegal? The functionality
seems to be identical.
- The EDG frontend seems to treat the mutable attribute differently in the
generation of the implicit copy constructor than in the generation of the
implicit copy assignment operator.
With kind regards,
W. Roehrl
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18975