]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/60497 (unique_ptr<T> tries to complete its type T even though it...
authorJonathan Wakely <jwakely@redhat.com>
Tue, 13 May 2014 11:18:01 +0000 (12:18 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 13 May 2014 11:18:01 +0000 (12:18 +0100)
PR libstdc++/60497
* include/std/tuple (get, __tuple_compare): Qualify more calls to
prevent ADL. Cast comparison results to bool.
* testsuite/20_util/tuple/60497.cc: Test accessing rvalues.
* testsuite/20_util/tuple/comparison_operators/overloaded.cc: New.

From-SVN: r210366

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/tuple
libstdc++-v3/testsuite/20_util/tuple/60497.cc
libstdc++-v3/testsuite/20_util/tuple/comparison_operators/overloaded.cc [new file with mode: 0644]

index 415a879cbd1082e11d8008f298bf5974f57806d9..9a776d1af62619a428947c9e67efd86a3754d3df 100644 (file)
@@ -1,3 +1,11 @@
+2014-05-13  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR libstdc++/60497
+       * include/std/tuple (get, __tuple_compare): Qualify more calls to
+       prevent ADL. Cast comparison results to bool.
+       * testsuite/20_util/tuple/60497.cc: Test accessing rvalues.
+       * testsuite/20_util/tuple/comparison_operators/overloaded.cc: New.
+
 2014-05-09  Jonathan Wakely  <jwakely@redhat.com>
 
        * config/abi/pre/gnu.ver (GLIBCXX_3.4.20): Correct regex_error export.
index 03d87d77aa0b67f8318d238b981dda188c5b5c6e..5e8766c3ffdfc5705702aa8589265696abab1160 100644 (file)
@@ -775,7 +775,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                     >::type
     get(tuple<_Elements...>&& __t) noexcept
     { return std::forward<typename tuple_element<__i,
-       tuple<_Elements...>>::type&&>(get<__i>(__t)); }
+       tuple<_Elements...>>::type&&>(std::get<__i>(__t)); }
 
 #if __cplusplus > 201103L
   template<typename _Head, size_t __i, typename... _Tail>
@@ -815,16 +815,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       static constexpr bool 
       __eq(const _Tp& __t, const _Up& __u)
       {
-       return (get<__i>(__t) == get<__i>(__u) &&
-               __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__eq(__t, __u));
+       return bool(std::get<__i>(__t) == std::get<__i>(__u))
+         && __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__eq(__t, __u);
       }
      
       static constexpr bool 
       __less(const _Tp& __t, const _Up& __u)
       {
-       return ((get<__i>(__t) < get<__i>(__u))
-               || !(get<__i>(__u) < get<__i>(__t)) &&
-               __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__less(__t, __u));
+       return bool(std::get<__i>(__t) < std::get<__i>(__u))
+         || !bool(std::get<__i>(__u) < std::get<__i>(__t))
+         && __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__less(__t, __u);
       }
     };
 
index 76d4223165f318a009ce649485a150511c98fd43..40d053b21681065464dd8decc2252430e1cea2bf 100644 (file)
@@ -35,3 +35,9 @@ auto a = std::get<0>(t);
 auto b = std::get<0>(ct);
 auto c = std::get<element_type>(t);
 auto d = std::get<element_type>(ct);
+
+// same again for rvalues
+auto e = std::get<0>(std::move(t));
+auto f = std::get<0>(std::move(ct));
+auto g = std::get<element_type>(std::move(t));
+auto h = std::get<element_type>(std::move(ct));
diff --git a/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/overloaded.cc b/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/overloaded.cc
new file mode 100644 (file)
index 0000000..0a343ae
--- /dev/null
@@ -0,0 +1,52 @@
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+// Copyright (C) 2014 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 3, 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 COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <tuple>
+
+// A type that is contextually convertible to bool but cannot be used with
+// the usual logical operators, and/or/not.
+struct TwistedLogic {
+  bool value;
+
+  explicit operator bool() const noexcept { return value; }
+};
+
+template<typename T>
+bool operator&&(const T&, TwistedLogic) = delete;
+
+template<typename T>
+bool operator&&(TwistedLogic, const T&) = delete;
+
+template<typename T>
+bool operator||(const T&, TwistedLogic) = delete;
+
+template<typename T>
+bool operator||(TwistedLogic, const T&) = delete;
+
+bool operator!(TwistedLogic) noexcept = delete;
+
+struct Compares {};
+
+TwistedLogic operator==(const Compares&, const Compares&) { return {true}; }
+TwistedLogic operator<(const Compares&, const Compares&) { return {false}; }
+
+auto a = std::make_tuple(nullptr, Compares{}, 2, 'U');
+auto b = a == a;
+auto c = a < a;