This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/48038] [C++0x] stable_sort problem with C++0x and comparator by value
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 9 Mar 2011 11:11:33 +0000
- Subject: [Bug libstdc++/48038] [C++0x] stable_sort problem with C++0x and comparator by value
- Auto-submitted: auto-generated
- References: <bug-48038-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48038
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2011.03.09 11:11:23
CC| |paolo.carlini at oracle dot
| |com
Summary|stable_sort problem with |[C++0x] stable_sort problem
|C++0x and comparator by |with C++0x and comparator
|value |by value
Ever Confirmed|0 |1
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-03-09 11:11:23 UTC ---
#include <algorithm>
#include <assert.h>
struct V
{
int val;
bool ok;
V(int v) : val(v), ok(true) { }
V(V const & rh) : val(rh.val), ok(rh.ok) {
assert(rh.ok);
}
V & operator=(V const &rh) {
assert(rh.ok);
val = rh.val;
ok = rh.ok;
return *this;
}
V(V && rh) : val(rh.val), ok(rh.ok) {
assert(rh.ok);
rh.ok = false;
}
V & operator=(V && rh) {
assert(rh.ok);
val = rh.val;
rh.ok = false;
return *this;
}
};
inline bool operator<(V lh, V rh) {
assert(rh.ok);
assert(lh.ok);
return lh.val < rh.val;
}
int main()
{
V vvs[] = { 2, 0 };
std::stable_sort(vvs, vvs+2);
}
The first element has ok=false after constructing the Temporary_buffer in
std::stable_sort, because __uninitialized_construct_buf_dispatch::__ucr uses
_GLIBCXX_MOVE which leaves vvs[0] in a moved-from state
Paolo, could you take a look?