public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/51866] New: [c++0x][4.7 Regression] unordered_set compares moved-out values
@ 2012-01-16  1:44 roman at binarylife dot net
  2012-01-16  1:51 ` [Bug libstdc++/51866] " paolo.carlini at oracle dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: roman at binarylife dot net @ 2012-01-16  1:44 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 51866
           Summary: [c++0x][4.7 Regression] unordered_set compares
                    moved-out values
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: roman@binarylife.net


$ cat test.cpp 
#include <unordered_set>
#include <iostream>
#include <cstdlib>

struct num {
  int value;
  num(int n)                 : value(n) {}
  num(num const&)            = default;
  num& operator=(num const&) = default;
  num(num&& o)               : value(o.value) { o.value=-1; }
  num& operator=(num&& o)    { if (this!=&o) { value=o.value; o.value=-1; }
return *this; }
};

struct num_hash {
  size_t operator()(num const& a)const {
    if (a.value<0) std::cout<<"hash of moved value"<<std::endl;
    return 0;
  }
};

struct num_equal {
  bool operator()(num const& a,num const& b)const {
    if (a.value<0 || b.value<0) {
      std::cout<<"compare of moved value: a="<<a.value<<",
b="<<b.value<<std::endl;
      return false;
    }
    return a.value==b.value;
  }
};

int main() {
  std::unordered_multiset<num,num_hash,num_equal> mset;
  mset.insert(num(1));
  mset.insert(num(2));
  mset.insert(num(1));
  mset.insert(num(2));
  if (mset.size()!=4) abort();
  auto iter=mset.cbegin();
  int x0=(iter++)->value;
  int x1=(iter++)->value;
  int x2=(iter++)->value;
  int x3=(iter++)->value;
  if ((x0==1 && x1==1 && x2==2 && x3==2) ||
      (x0==2 && x1==2 && x2==1 && x3==1)) return 0;
  std::cout<<x0<<' '<<x1<<' '<<x2<<' '<<x3<<std::endl;
  abort();
}

$ g++ -std=c++0x test.cpp && ./a.out 
compare of moved value: a=-1, b=1
compare of moved value: a=-1, b=2
compare of moved value: a=-1, b=1
compare of moved value: a=-1, b=1
compare of moved value: a=-1, b=2
compare of moved value: a=-1, b=1
2 1 2 1
Aborted


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

end of thread, other threads:[~2012-01-18 20:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-16  1:44 [Bug libstdc++/51866] New: [c++0x][4.7 Regression] unordered_set compares moved-out values roman at binarylife dot net
2012-01-16  1:51 ` [Bug libstdc++/51866] " paolo.carlini at oracle dot com
2012-01-16  1:53 ` [Bug libstdc++/51866] [c++0x][4.7 Regression] unordered_multiset " roman at binarylife dot net
2012-01-16  2:53 ` paolo.carlini at oracle dot com
2012-01-16  3:31 ` paolo.carlini at oracle dot com
2012-01-16 12:21 ` paolo.carlini at oracle dot com
2012-01-16 12:40 ` redi at gcc dot gnu.org
2012-01-16 12:54 ` redi at gcc dot gnu.org
2012-01-16 12:56 ` redi at gcc dot gnu.org
2012-01-18 20:31 ` fdumont at gcc dot gnu.org
2012-01-18 20:53 ` fdumont at gcc dot gnu.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).