]> gcc.gnu.org Git - gcc.git/commitdiff
re PR libstdc++/37547 ([c++0x] minmax with initializer_list gives incorrect results)
authorPaolo Carlini <paolo.carlini@oracle.com>
Wed, 17 Sep 2008 22:58:38 +0000 (22:58 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 17 Sep 2008 22:58:38 +0000 (22:58 +0000)
2008-09-17  Paolo Carlini  <paolo.carlini@oracle.com>

PR libstdc++/37547
* include/bits/stl_algo.h (min(initializer_list<>),
min(initializer_list<>, Compare), max(initializer_list<>),
max(initializer_list<>, Compare), minmax(initializer_list<>),
minmax(initializer_list<>, Compare)): Fix return type.
* include/bits/algorithmfwd.h: Adjust.
* testsuite/25_algorithms/headers/algorithm/synopsis.cc: Likewise.
* testsuite/25_algorithms/max/requirements/explicit_instantiation/3.cc:
        Likewise.
        * testsuite/25_algorithms/max/requirements/explicit_instantiation/
        pod2.cc: Likewise.
* testsuite/25_algorithms/min/requirements/explicit_instantiation/3.cc:
        Likewise.
        * testsuite/25_algorithms/min/requirements/explicit_instantiation/
        pod2.cc: Likewise.
* testsuite/25_algorithms/minmax/requirements/explicit_instantiation/
3.cc: Likewise.
        * testsuite/25_algorithms/minmax/requirements/explicit_instantiation/
        pod2.cc: Likewise.
* testsuite/25_algorithms/max/37547.cc: New.
* testsuite/25_algorithms/min/37547.cc: Likewise.
* testsuite/25_algorithms/minmax/37547.cc: Likewise.

From-SVN: r140435

13 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/algorithmfwd.h
libstdc++-v3/include/bits/stl_algo.h
libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc
libstdc++-v3/testsuite/25_algorithms/max/37547.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/max/requirements/explicit_instantiation/3.cc
libstdc++-v3/testsuite/25_algorithms/max/requirements/explicit_instantiation/pod2.cc
libstdc++-v3/testsuite/25_algorithms/min/37547.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/min/requirements/explicit_instantiation/3.cc
libstdc++-v3/testsuite/25_algorithms/min/requirements/explicit_instantiation/pod2.cc
libstdc++-v3/testsuite/25_algorithms/minmax/37547.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/minmax/requirements/explicit_instantiation/3.cc
libstdc++-v3/testsuite/25_algorithms/minmax/requirements/explicit_instantiation/pod2.cc

index 3c2d291778e18e63f23e890c892bac7b87b5f46b..0d9e413faa3a804aa91acd9675bd0ee721e2e470 100644 (file)
@@ -1,3 +1,28 @@
+2008-09-17  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR libstdc++/37547
+       * include/bits/stl_algo.h (min(initializer_list<>),
+       min(initializer_list<>, Compare), max(initializer_list<>),
+       max(initializer_list<>, Compare), minmax(initializer_list<>),
+       minmax(initializer_list<>, Compare)): Fix return type.
+       * include/bits/algorithmfwd.h: Adjust.
+       * testsuite/25_algorithms/headers/algorithm/synopsis.cc: Likewise.
+       * testsuite/25_algorithms/max/requirements/explicit_instantiation/3.cc:
+        Likewise.
+        * testsuite/25_algorithms/max/requirements/explicit_instantiation/
+        pod2.cc: Likewise.
+       * testsuite/25_algorithms/min/requirements/explicit_instantiation/3.cc:
+        Likewise.
+        * testsuite/25_algorithms/min/requirements/explicit_instantiation/
+        pod2.cc: Likewise.
+       * testsuite/25_algorithms/minmax/requirements/explicit_instantiation/
+       3.cc: Likewise.
+        * testsuite/25_algorithms/minmax/requirements/explicit_instantiation/
+        pod2.cc: Likewise.
+       * testsuite/25_algorithms/max/37547.cc: New.
+       * testsuite/25_algorithms/min/37547.cc: Likewise.
+       * testsuite/25_algorithms/minmax/37547.cc: Likewise.
+
 2008-09-16  Chris Fairles  <chris.fairles@gmail.com>
 
         * testsuite/25_algorithms/min/requirements/explicit_instantiation/3.cc:
index 95ff72b79d5f99572c24480b75f5d50c406f7e4d..0e2e2c0e277638dc268128d1c89f06c150c7096a 100644 (file)
@@ -319,27 +319,27 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     minmax_element(_FIter, _FIter, _Compare);
 
   template<typename _Tp>
-    const _Tp&
+    _Tp
     min(initializer_list<_Tp>);
 
   template<typename _Tp, typename _Compare>
-    const _Tp&
+    _Tp
     min(initializer_list<_Tp>, _Compare);
 
   template<typename _Tp>
-    const _Tp&
+    _Tp
     max(initializer_list<_Tp>);
 
   template<typename _Tp, typename _Compare>
-    const _Tp&
+    _Tp
     max(initializer_list<_Tp>, _Compare);
 
   template<typename _Tp>
-    pair<const _Tp&, const _Tp&>
+    pair<_Tp, _Tp>
     minmax(initializer_list<_Tp>);
 
   template<typename _Tp, typename _Compare>
-    pair<const _Tp&, const _Tp&>
+    pair<_Tp, _Tp>
     minmax(initializer_list<_Tp>, _Compare);
 #endif
 
index 42ada9986f399e350c3a0bb6db6f3d85d6d4dbb1..373881c7f1b36c7378a3bbfad0549a7c63046070 100644 (file)
@@ -4094,38 +4094,38 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       return std::make_pair(__min, __max);
     }
 
-  // N2722.
+  // N2722 + fixes.
   template<typename _Tp>
-    inline const _Tp&
+    inline _Tp
     min(initializer_list<_Tp> __l)
     { return *std::min_element(__l.begin(), __l.end()); }
 
   template<typename _Tp, typename _Compare>
-    inline const _Tp&
+    inline _Tp
     min(initializer_list<_Tp> __l, _Compare __comp)
     { return *std::min_element(__l.begin(), __l.end(), __comp); }
 
   template<typename _Tp>
-    inline const _Tp&
+    inline _Tp
     max(initializer_list<_Tp> __l)
     { return *std::max_element(__l.begin(), __l.end()); }
 
   template<typename _Tp, typename _Compare>
-    inline const _Tp&
+    inline _Tp
     max(initializer_list<_Tp> __l, _Compare __comp)
     { return *std::max_element(__l.begin(), __l.end(), __comp); }
 
   template<typename _Tp>
-    inline pair<const _Tp&, const _Tp&>
+    inline pair<_Tp, _Tp>
     minmax(initializer_list<_Tp> __l)
     {
       pair<const _Tp*, const _Tp*> __p =
        std::minmax_element(__l.begin(), __l.end());
-      return std::make_pair(*__p.first, *__p.second);
+      return std::pair<_Tp, _Tp>(*__p.first, *__p.second);
     }
 
   template<typename _Tp, typename _Compare>
-    inline pair<const _Tp&, const _Tp&>
+    inline pair<_Tp, _Tp>
     minmax(initializer_list<_Tp> __l, _Compare __comp)
     {
       pair<const _Tp*, const _Tp*> __p =
index 3bc8eb2a7649bafaf34795aab7214a65f529f890..aa4496b907b56dfe8d5cba39af884611e463b2bc 100644 (file)
@@ -533,27 +533,27 @@ namespace std
     minmax_element(_FIter, _FIter, _Compare);
 
   template<typename _Tp>
-    const _Tp&
+    _Tp
     min(initializer_list<_Tp>);
 
   template<typename _Tp, typename _Compare>
-    const _Tp&
+    _Tp
     min(initializer_list<_Tp>, _Compare);
 
   template<typename _Tp>
-    const _Tp&
+    _Tp
     max(initializer_list<_Tp>);
 
   template<typename _Tp, typename _Compare>
-    const _Tp&
+    _Tp
     max(initializer_list<_Tp>, _Compare);
 
   template<typename _Tp>
-    pair<const _Tp&, const _Tp&>
+    pair<_Tp, _Tp>
     minmax(initializer_list<_Tp>);
 
   template<typename _Tp, typename _Compare>
-    pair<const _Tp&, const _Tp&>
+    pair<_Tp, _Tp>
     minmax(initializer_list<_Tp>, _Compare);
 #endif
 
diff --git a/libstdc++-v3/testsuite/25_algorithms/max/37547.cc b/libstdc++-v3/testsuite/25_algorithms/max/37547.cc
new file mode 100644 (file)
index 0000000..233804c
--- /dev/null
@@ -0,0 +1,40 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2008 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 <algorithm>
+#include <vector>
+#include <testsuite_hooks.h>
+
+// libstdc++/37547
+int test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  std::vector<int> v{1,2,3,4,5};
+
+  auto p = std::max({v});
+  VERIFY ( p == v );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
index e4ac6cb607b45ca507bf28afaed4bc67ac0af50e..1f242c9af3906c098441f641c5eaa7b5642f624f 100644 (file)
@@ -42,6 +42,6 @@ namespace std
   typedef value_type*          iterator_type;
   typedef std::less<value_type> compare_type;
 
-  template const value_type&  max(initializer_list<value_type>);
-  template const value_type&  max(initializer_list<value_type>, compare_type);
+  template value_type max(initializer_list<value_type>);
+  template value_type max(initializer_list<value_type>, compare_type);
 } 
index 55f2eae6545289cf454e7ba4066f0bd27f542222..0e623e2e637a2320fd9b17100de2c920069c452e 100644 (file)
@@ -42,6 +42,6 @@ namespace std
   typedef value_type*          iterator_type;
   typedef std::less<value_type> compare_type;
 
-  template const value_type&  max(initializer_list<value_type>);
-  template const value_type&  max(initializer_list<value_type>, compare_type);
+  template value_type max(initializer_list<value_type>);
+  template value_type max(initializer_list<value_type>, compare_type);
 } 
diff --git a/libstdc++-v3/testsuite/25_algorithms/min/37547.cc b/libstdc++-v3/testsuite/25_algorithms/min/37547.cc
new file mode 100644 (file)
index 0000000..5d0ffd4
--- /dev/null
@@ -0,0 +1,40 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2008 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 <algorithm>
+#include <vector>
+#include <testsuite_hooks.h>
+
+// libstdc++/37547
+int test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  std::vector<int> v{1,2,3,4,5};
+
+  auto p = std::min({v});
+  VERIFY ( p == v );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
index 1d6e7aedeb887f98c4e5a89769aa2b11ed9f6cb4..7faea37947c2c68d69b272ae01835b3d04a2642d 100644 (file)
@@ -42,6 +42,6 @@ namespace std
   typedef value_type*          iterator_type;
   typedef std::less<value_type> compare_type;
 
-  template const value_type&  min(initializer_list<value_type>);
-  template const value_type&  min(initializer_list<value_type>, compare_type);
+  template value_type min(initializer_list<value_type>);
+  template value_type min(initializer_list<value_type>, compare_type);
 } 
index 98c8413c2a62f4e8386017eb5d8a8b373f007bad..4800c1bd1c5913398bd00a151dcdcb9955b2fb31 100644 (file)
@@ -42,6 +42,6 @@ namespace std
   typedef value_type*          iterator_type;
   typedef std::less<value_type> compare_type;
 
-  template const value_type&  min(initializer_list<value_type>);
-  template const value_type&  min(initializer_list<value_type>, compare_type);
+  template value_type min(initializer_list<value_type>);
+  template value_type min(initializer_list<value_type>, compare_type);
 } 
diff --git a/libstdc++-v3/testsuite/25_algorithms/minmax/37547.cc b/libstdc++-v3/testsuite/25_algorithms/minmax/37547.cc
new file mode 100644 (file)
index 0000000..21de390
--- /dev/null
@@ -0,0 +1,40 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2008 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 <algorithm>
+#include <vector>
+#include <testsuite_hooks.h>
+
+// libstdc++/37547
+int test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  std::vector<int> v{1,2,3,4,5};
+
+  auto p = std::minmax({v});
+  VERIFY ( p.first == v );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
index 71fab66fddd68419dd2c2c51ea76f19690c6ccda..a6506ca764cd692db946a24035c9278e0fee3cdd 100644 (file)
@@ -42,8 +42,7 @@ namespace std
   typedef value_type*          iterator_type;
   typedef std::less<value_type> compare_type;
 
-  template pair<const value_type&, const value_type&>
-    minmax(initializer_list<value_type>);
-  template pair<const value_type&, const value_type&>
-    minmax(initializer_list<value_type>, compare_type);
+  template pair<value_type, value_type> minmax(initializer_list<value_type>);
+  template pair<value_type, value_type> minmax(initializer_list<value_type>,
+                                              compare_type);
 }
index d5285930ddf5dc4f7fd09322c7e68b87a5d2d7dc..b31d38d3c8918d43c6e98d2bea6772232b56bd19 100644 (file)
@@ -42,8 +42,7 @@ namespace std
   typedef value_type*          iterator_type;
   typedef std::less<value_type> compare_type;
 
-  template pair<const value_type&, const value_type&>
-    minmax(initializer_list<value_type>);
-  template pair<const value_type&, const value_type&>
-    minmax(initializer_list<value_type>, compare_type);
+  template pair<value_type, value_type> minmax(initializer_list<value_type>);
+  template pair<value_type, value_type> minmax(initializer_list<value_type>,
+                                              compare_type);
 }
This page took 0.091853 seconds and 5 git commands to generate.