From c5be97a5f06992fd2c9589268c322aead79fb689 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Tue, 1 Jan 2008 16:42:34 +0000 Subject: [PATCH] re PR libstdc++/34636 (Parallel sort fails) 2008-01-01 Paolo Carlini PR libstdc++/34636 * include/parallel/algobase.h (lexicographical_compare_switch(..., random_access_iterator_tag, random_access_iterator_tag)): Careful with undereferenceable iterators. * testsuite/25_algorithms/sort/34636.cc: New. From-SVN: r131245 --- libstdc++-v3/ChangeLog | 8 +++++ libstdc++-v3/include/parallel/algobase.h | 16 ++------- .../testsuite/25_algorithms/sort/34636.cc | 33 +++++++++++++++++++ 3 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 libstdc++-v3/testsuite/25_algorithms/sort/34636.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 5b472c06837..ce044da2873 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2008-01-01 Paolo Carlini + + PR libstdc++/34636 + * include/parallel/algobase.h (lexicographical_compare_switch(..., + random_access_iterator_tag, random_access_iterator_tag)): Careful + with undereferenceable iterators. + * testsuite/25_algorithms/sort/34636.cc: New. + 2007-12-30 Paolo Carlini * include/std/tuple (_Tuple_impl<>::_Tuple_impl(typename diff --git a/libstdc++-v3/include/parallel/algobase.h b/libstdc++-v3/include/parallel/algobase.h index 8e9438d8a8d..39e9062faae 100644 --- a/libstdc++-v3/include/parallel/algobase.h +++ b/libstdc++-v3/include/parallel/algobase.h @@ -215,13 +215,7 @@ namespace __parallel random_access_iterator_tag(), random_access_iterator_tag()); - // Less because shorter. - const bool lbs = mm.first == end1; - - // Less because differing elements less. - const bool lbdel = pred(*mm.first, *mm.second); - - return lbs || lbdel; + return (mm.first == end1) || bool(pred(*mm.first, *mm.second)); } else { @@ -231,13 +225,7 @@ namespace __parallel random_access_iterator_tag(), random_access_iterator_tag()); - // Less because shorter. - const bool lbs = mm.first != end2; - - // Less because differing element less. - const bool lbdel = pred(*mm.second, *mm.first); - - return lbs && lbdel; + return (mm.first != end2) && bool(pred(*mm.second, *mm.first)); } } else diff --git a/libstdc++-v3/testsuite/25_algorithms/sort/34636.cc b/libstdc++-v3/testsuite/25_algorithms/sort/34636.cc new file mode 100644 index 00000000000..61fa4d52247 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/sort/34636.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include + +// libstdc++/34636 +void test01() +{ + std::vector > v(2); + std::sort(v.begin(), v.end()); +} + +int main() +{ + test01(); + return 0; +}