From 75e75a087d4aca27ced05a540a858358301eee92 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 13 May 2014 12:18:01 +0100 Subject: [PATCH] re PR libstdc++/60497 (unique_ptr tries to complete its type T even though it's not required to be a complete type) 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 | 8 +++ libstdc++-v3/include/std/tuple | 12 ++--- libstdc++-v3/testsuite/20_util/tuple/60497.cc | 6 +++ .../tuple/comparison_operators/overloaded.cc | 52 +++++++++++++++++++ 4 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/tuple/comparison_operators/overloaded.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 415a879cbd1..9a776d1af62 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2014-05-13 Jonathan Wakely + + 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 * config/abi/pre/gnu.ver (GLIBCXX_3.4.20): Correct regex_error export. diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index 03d87d77aa0..5e8766c3ffd 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -775,7 +775,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION >::type get(tuple<_Elements...>&& __t) noexcept { return std::forward>::type&&>(get<__i>(__t)); } + tuple<_Elements...>>::type&&>(std::get<__i>(__t)); } #if __cplusplus > 201103L template @@ -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); } }; diff --git a/libstdc++-v3/testsuite/20_util/tuple/60497.cc b/libstdc++-v3/testsuite/20_util/tuple/60497.cc index 76d4223165f..40d053b2168 100644 --- a/libstdc++-v3/testsuite/20_util/tuple/60497.cc +++ b/libstdc++-v3/testsuite/20_util/tuple/60497.cc @@ -35,3 +35,9 @@ auto a = std::get<0>(t); auto b = std::get<0>(ct); auto c = std::get(t); auto d = std::get(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(std::move(t)); +auto h = std::get(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 index 00000000000..0a343ae19d5 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/overloaded.cc @@ -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 +// . + +#include + +// 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 +bool operator&&(const T&, TwistedLogic) = delete; + +template +bool operator&&(TwistedLogic, const T&) = delete; + +template +bool operator||(const T&, TwistedLogic) = delete; + +template +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;