public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/49559] New: stable_sort calls self-move-assignment operator
@ 2011-06-28  6:56 joerg.richter@pdv-fs.de
  2011-06-28  8:41 ` [Bug libstdc++/49559] " redi at gcc dot gnu.org
                   ` (25 more replies)
  0 siblings, 26 replies; 27+ messages in thread
From: joerg.richter@pdv-fs.de @ 2011-06-28  6:56 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: stable_sort calls self-move-assignment operator
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: joerg.richter@pdv-fs.de


$ cat t.cc
#include <cassert>
#include <algorithm>
#include <iostream>

struct MyMoveClass
{
    int val_;

    explicit MyMoveClass( int val = 0 )
      : val_( val )
    {
      std::cout << "ctr this=" << this << std::endl;
    }

    MyMoveClass( MyMoveClass const& rhs )
      : val_( rhs.val_ )
    {
      std::cout << "ctr copy this=" << this << " rhs=" << &rhs << std::endl;
    }

    MyMoveClass( MyMoveClass && rhs )
      : val_( rhs.val_ )
    {
      std::cout << "ctr move this=" << this << " rhs=" << &rhs << std::endl;
      rhs.val_ = 0;
    }

    MyMoveClass& operator=( MyMoveClass && rhs )
    {
      std::cout << "assign move this=" << this << " rhs=" << &rhs << std::endl;
      assert( this != &rhs );
      val_ = rhs.val_;
      rhs.val_ = 0;
      return *this;
    }

    MyMoveClass& operator=( MyMoveClass const& rhs )
    {
      std::cout << "assign copy this=" << this << " rhs=" << &rhs << std::endl;
      val_ = rhs.val_;
      return *this;
    }

    ~MyMoveClass()
    {
      std::cout << "dtr this=" << this << std::endl;
    }

    bool operator<( MyMoveClass const& rhs ) const
    {
      return val_ < rhs.val_;
    }
};

int main()
{
  MyMoveClass v(5);
  std::stable_sort( &v, &v+1 );
  return 0;
}


$ g++ -std=gnu++0x -o t t.cc

$ ./t
ctr this=0xbfe1730c
ctr move this=0x8afd008 rhs=0xbfe1730c
assign move this=0xbfe1730c rhs=0x8afd008
assign move this=0xbfe1730c rhs=0xbfe1730c
template: template.cc:31: MyMoveClass& MyMoveClass::operator=(MyMoveClass&&):
Assertion `this != &rhs' failed.


>From DR 1204: "Additionally this clarifies that move assignment operators need
not perform the traditional if (this != &rhs) test commonly found (and needed)
in copy assignment operators."

Note that std::sort() calls no copy constructor or assignment operator at all. 
Seems sensible when there is only one element.


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

end of thread, other threads:[~2011-09-27  8:24 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-28  6:56 [Bug libstdc++/49559] New: stable_sort calls self-move-assignment operator joerg.richter@pdv-fs.de
2011-06-28  8:41 ` [Bug libstdc++/49559] " redi at gcc dot gnu.org
2011-06-28  8:56 ` redi at gcc dot gnu.org
2011-06-28  9:45 ` paolo.carlini at oracle dot com
2011-06-28  9:49 ` paolo.carlini at oracle dot com
2011-06-28 10:41 ` [Bug libstdc++/49559] [C++0x] " paolo.carlini at oracle dot com
2011-06-28 10:46 ` redi at gcc dot gnu.org
2011-06-28 10:57 ` paolo.carlini at oracle dot com
2011-06-28 10:59 ` paolo.carlini at oracle dot com
2011-06-28 13:38 ` paolo.carlini at oracle dot com
2011-06-28 14:12 ` paolo.carlini at oracle dot com
2011-06-28 14:12 ` paolo.carlini at oracle dot com
2011-06-28 16:23 ` paolo.carlini at oracle dot com
2011-06-28 18:07 ` paolo.carlini at oracle dot com
2011-06-28 19:16 ` chris at bubblescope dot net
2011-06-28 19:39 ` paolo.carlini at oracle dot com
2011-07-07  9:54 ` paolo.carlini at oracle dot com
2011-07-08 11:01 ` paolo.carlini at oracle dot com
2011-07-08 11:47 ` paolo.carlini at oracle dot com
2011-07-08 15:47 ` paolo.carlini at oracle dot com
2011-07-08 16:23 ` paolo.carlini at oracle dot com
2011-07-11 18:40 ` paolo at gcc dot gnu.org
2011-07-11 18:43 ` paolo.carlini at oracle dot com
2011-07-13 15:14 ` joerg.richter@pdv-fs.de
2011-07-13 15:20 ` paolo.carlini at oracle dot com
2011-09-27  8:31 ` paolo at gcc dot gnu.org
2011-09-27  8:31 ` paolo.carlini at oracle dot com

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).