diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2018-07-16 18:13:41 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2018-07-16 18:13:41 +0100 |
commit | 20b47be02cc8a1bde28519b496a5acea5419c995 (patch) | |
tree | 24156815bed6f991ee7acdf1d1d62a0fc4e41642 | |
parent | 2ee1228ecd5f5c6e3ff4ac07e4b7f45c79211576 (diff) | |
download | gcc-20b47be02cc8a1bde28519b496a5acea5419c995.zip gcc-20b47be02cc8a1bde28519b496a5acea5419c995.tar.gz gcc-20b47be02cc8a1bde28519b496a5acea5419c995.tar.bz2 |
PR libstdc++/86537 remove less<shared_ptr<T>> partial specialization
The standard doesn't specify this partial specialization (it was
required after the changes in N2637 but then should have been removed
following LWG 1262). Its presence is observable because it causes
different results when operator< has been overloaded for a shared_ptr
specialization.
PR libstdc++/86537
* include/bits/shared_ptr.h (less<shared_ptr<_Tp>>): Remove
non-standard partial specialization.
* include/bits/shared_ptr_base.h (_Sp_less): Remove class definition.
(less<__shared_ptr<_Tp, _Lp>): Remove partial specialization.
* testsuite/20_util/shared_ptr/comparison/86537.cc: New test.
From-SVN: r262739
-rw-r--r-- | libstdc++-v3/ChangeLog | 9 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/shared_ptr.h | 4 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/shared_ptr_base.h | 16 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/shared_ptr/comparison/86537.cc | 69 |
4 files changed, 78 insertions, 20 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ccf7c9e..cad6661 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2018-07-16 Jonathan Wakely <jwakely@redhat.com> + + PR libstdc++/86537 + * include/bits/shared_ptr.h (less<shared_ptr<_Tp>>): Remove + non-standard partial specialization. + * include/bits/shared_ptr_base.h (_Sp_less): Remove class definition. + (less<__shared_ptr<_Tp, _Lp>): Remove partial specialization. + * testsuite/20_util/shared_ptr/comparison/86537.cc: New test. + 2018-07-16 Andreas Krebbel <krebbel@linux.ibm.com> * config/abi/post/s390-linux-gnu/baseline_symbols.txt: Update. diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index 2a54145..2a82f18 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -480,10 +480,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator>=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept { return !(nullptr < __a); } - template<typename _Tp> - struct less<shared_ptr<_Tp>> : public _Sp_less<shared_ptr<_Tp>> - { }; - // 20.7.2.2.8 shared_ptr specialized algorithms. template<typename _Tp> inline void diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index 887edbd..f3994da 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -1502,22 +1502,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator>=(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept { return !(nullptr < __a); } - template<typename _Sp> - struct _Sp_less : public binary_function<_Sp, _Sp, bool> - { - bool - operator()(const _Sp& __lhs, const _Sp& __rhs) const noexcept - { - typedef typename _Sp::element_type element_type; - return std::less<element_type*>()(__lhs.get(), __rhs.get()); - } - }; - - template<typename _Tp, _Lock_policy _Lp> - struct less<__shared_ptr<_Tp, _Lp>> - : public _Sp_less<__shared_ptr<_Tp, _Lp>> - { }; - // 20.7.2.2.8 shared_ptr specialized algorithms. template<typename _Tp, _Lock_policy _Lp> inline void diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/comparison/86537.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/comparison/86537.cc new file mode 100644 index 0000000..c8440a3 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/comparison/86537.cc @@ -0,0 +1,69 @@ +// Copyright (C) 2018 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/>. + +// { dg-do run { target c++11 } } + +#include <memory> +#include <testsuite_hooks.h> + +struct Should_not_happen { }; + +struct X { }; + +namespace std { + template<> struct less<X*> { + bool operator()(X*, X*) const { throw Should_not_happen(); } + }; +} + +bool custom_op_called = false; + +bool +operator<(const std::shared_ptr<X>&, const std::shared_ptr<X>&) +{ + custom_op_called = true; + return false; +} + +void +test01() +{ + const std::shared_ptr<X> sp; + bool b = sp < sp; + VERIFY( !b ); + VERIFY( custom_op_called ); + + std::less<std::shared_ptr<X>> lt; + custom_op_called = false; + b = lt(sp, sp); + VERIFY( !b ); + VERIFY( custom_op_called ); // PR libstdc++/86537 and LWG DR 1262 + +#if __cplusplus >= 201402L + std::less<> ltv; + custom_op_called = false; + b = ltv(sp, sp); + VERIFY( !b ); + VERIFY( custom_op_called ); +#endif +} + +int +main() +{ + test01(); +} |