public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/24488]  New: GCC should warn about poorly implemented copy assignment operators
@ 2005-10-22 21:57 tron dot thomas at verizon dot net
  2005-10-22 22:02 ` [Bug c++/24488] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: tron dot thomas at verizon dot net @ 2005-10-22 21:57 UTC (permalink / raw)
  To: gcc-bugs

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


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

* [Bug c++/24488] GCC should warn about poorly implemented copy assignment operators
  2005-10-22 21:57 [Bug c++/24488] New: GCC should warn about poorly implemented copy assignment operators tron dot thomas at verizon dot net
@ 2005-10-22 22:02 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-10-22 22:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2005-10-22 22:02 -------
Use -O1 -Wuninitialize and use another.m_flag and you will see that it warns
about that.  Copy constructs and copy assignment operators should never be
treated special.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

end of thread, other threads:[~2005-10-22 22:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-22 21:57 [Bug c++/24488] New: GCC should warn about poorly implemented copy assignment operators tron dot thomas at verizon dot net
2005-10-22 22:02 ` [Bug c++/24488] " pinskia 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).