This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/24488] New: GCC should warn about poorly implemented copy assignment operators
- From: "tron dot thomas at verizon dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 22 Oct 2005 21:57:10 -0000
- Subject: [Bug c++/24488] New: GCC should warn about poorly implemented copy assignment operators
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
It would be nice for the C++ compiler to warn users when they implement copy
assignment operator that does not copy all parts of an object.
Build the following (contrived) program at maximum warning level:
class Copy
{
public:
Copy() : m_value(0), m_flag(false) {}
Copy& operator=(const Copy& source)
{
m_value = source.m_value;
return *this;
}
private:
int m_value;
bool m_flag;
};
int main()
{
Copy instance;
Copy another;
another = instance;
return 0;
}
Results:
No warning will results
Expected:
The C++ compiler could warn the user that certain members (i.e. m_flag) are not
copied in the implementation of the copy assignment operator.
--
Summary: GCC should warn about poorly implemented copy assignment
operators
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P5
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tron dot thomas at verizon dot net
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24488