public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/52822] New: [C++11] stable_partition destroys sequence due to inappropriate self-move-assignment
@ 2012-04-01 18:51 jyasskin at gcc dot gnu.org
  2012-04-01 20:42 ` [Bug libstdc++/52822] " jyasskin at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: jyasskin at gcc dot gnu.org @ 2012-04-01 18:51 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52822
           Summary: [C++11] stable_partition destroys sequence due to
                    inappropriate self-move-assignment
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jyasskin@gcc.gnu.org


The following test program should print "1" twice, since stable_partition is
only supposed to rearrange values, not modify them.

$ cat test.cc
#include <vector>
#include <utility>
#include <algorithm>
#include <iostream>
using namespace std;

bool pred(const vector<int>&) { return true; }

int main() {
  vector<vector<int> > v(1);
  v[0].push_back(7);
  cout << v[0].size() << '\n';
  stable_partition(v.begin(), v.end(), pred);
  cout << v[0].size() << '\n';
}
$ g++-4.6pre --version
g++-4.6pre (GCC) 4.6.4 20120330 (prerelease)
$ g++-4.6pre -std=c++98 -g3 test.cc -o test && ./test
1
1
$ g++-4.6pre -std=c++0x -g3 test.cc -o test && ./test
1
0
$ g++-4.7pre --version
g++-4.7pre (GCC) 4.7.1 20120330 (prerelease)
$ g++-4.7pre   -std=c++0x -g3 test.cc -o test && ./test
1
0
$ g++-4.8pre --version
g++-4.8pre (GCC) 4.8.0 20120330 (experimental)
$ g++-4.8pre -std=c++0x -g3 test.cc -o test && ./test
1
0


I believe this happens because
http://gcc.gnu.org/viewcvs/trunk/libstdc%2B%2B-v3/include/bits/stl_algo.h?revision=184997&view=markup#l1827
move-assigns *__result1 from *__first even when those are the same object,
which violates
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#1204.

I haven't audited the rest of the library to look for more instances of this
mistake. I'm planning to switch the default compilation mode to c++0x and run
the gcc-4.6 test suite to look for more problems, but I'm not currently
planning to do the same for 4.7 or trunk.


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

end of thread, other threads:[~2012-04-12 22:30 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-01 18:51 [Bug libstdc++/52822] New: [C++11] stable_partition destroys sequence due to inappropriate self-move-assignment jyasskin at gcc dot gnu.org
2012-04-01 20:42 ` [Bug libstdc++/52822] " jyasskin at gcc dot gnu.org
2012-04-01 21:15 ` redi at gcc dot gnu.org
2012-04-01 21:51 ` paolo.carlini at oracle dot com
2012-04-01 22:10 ` paolo.carlini at oracle dot com
2012-04-02  2:15 ` jyasskin at gcc dot gnu.org
2012-04-02  9:10 ` paolo.carlini at oracle dot com
2012-04-02 16:41 ` jyasskin at gcc dot gnu.org
2012-04-12 12:21 ` paolo.carlini at oracle dot com
2012-04-12 20:59 ` jyasskin at gcc dot gnu.org
2012-04-12 21:42 ` jyasskin at gcc dot gnu.org
2012-04-12 22:26 ` jyasskin at gcc dot gnu.org
2012-04-12 22:30 ` jyasskin 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).