From: Paolo Carlini Date: Tue, 22 Mar 2011 15:15:03 +0000 (+0000) Subject: shared_ptr.h (operator>, [...]): Add, per DR 1401. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=355e71b9df357e5874dc46bd24967f00be6c5a83;p=gcc.git shared_ptr.h (operator>, [...]): Add, per DR 1401. 2011-03-22 Paolo Carlini * include/bits/shared_ptr.h (operator>, operator<=, operator>=): Add, per DR 1401. (operator==, operator!=, operator<): Fix per the letter of DR 1401. * include/bits/shared_ptr_base.h: Likewise for __shared_ptr. * include/bits/unique_ptr.h (operator==, operator!=, operator<, operator<=, operator>, operator>=): Fix per the letter of DR 1401. * testsuite/20_util/shared_ptr/comparison/dr1401.cc: New. * testsuite/20_util/unique_ptr/comparison/dr1401.cc: Likewise. * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust. From-SVN: r171293 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c5200f6c4be..3adde1d8eb0 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,15 @@ +2011-03-22 Paolo Carlini + + * include/bits/shared_ptr.h (operator>, operator<=, operator>=): Add, + per DR 1401. + (operator==, operator!=, operator<): Fix per the letter of DR 1401. + * include/bits/shared_ptr_base.h: Likewise for __shared_ptr. + * include/bits/unique_ptr.h (operator==, operator!=, operator<, + operator<=, operator>, operator>=): Fix per the letter of DR 1401. + * testsuite/20_util/shared_ptr/comparison/dr1401.cc: New. + * testsuite/20_util/unique_ptr/comparison/dr1401.cc: Likewise. + * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust. + 2011-03-22 Jakub Jelinek * config/abi/pre/gnu.ver (GLIBCXX_3.4.15): Export _ZNSsC2EOSs diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index 97d123f942b..490810cabf6 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -321,38 +321,102 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // 20.8.13.2.7 shared_ptr comparisons template inline bool - operator==(const shared_ptr<_Tp1>& __a, const shared_ptr<_Tp2>& __b) + operator==(const shared_ptr<_Tp1>& __a, + const shared_ptr<_Tp2>& __b) noexcept { return __a.get() == __b.get(); } template inline bool - operator==(const shared_ptr<_Tp>& __a, nullptr_t) - { return __a.get() == nullptr; } + operator==(const shared_ptr<_Tp>& __a, nullptr_t) noexcept + { return !__a; } template inline bool - operator==(nullptr_t, const shared_ptr<_Tp>& __b) - { return nullptr == __b.get(); } + operator==(nullptr_t, const shared_ptr<_Tp>& __a) noexcept + { return !__a; } template inline bool - operator!=(const shared_ptr<_Tp1>& __a, const shared_ptr<_Tp2>& __b) + operator!=(const shared_ptr<_Tp1>& __a, + const shared_ptr<_Tp2>& __b) noexcept { return __a.get() != __b.get(); } template inline bool - operator!=(const shared_ptr<_Tp>& __a, nullptr_t) - { return __a.get() != nullptr; } + operator!=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept + { return (bool)__a; } template inline bool - operator!=(nullptr_t, const shared_ptr<_Tp>& __b) - { return nullptr != __b.get(); } + operator!=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept + { return (bool)__a; } template inline bool - operator<(const shared_ptr<_Tp1>& __a, const shared_ptr<_Tp2>& __b) - { return __a.get() < __b.get(); } + operator<(const shared_ptr<_Tp1>& __a, + const shared_ptr<_Tp2>& __b) noexcept + { + typedef typename std::common_type<_Tp1*, _Tp2*>::type _CT; + return std::less<_CT>()(__a.get(), __b.get()); + } + + template + inline bool + operator<(const shared_ptr<_Tp>& __a, nullptr_t) noexcept + { return std::less<_Tp*>()(__a.get(), nullptr); } + + template + inline bool + operator<(nullptr_t, const shared_ptr<_Tp>& __a) noexcept + { return std::less<_Tp*>()(nullptr, __a.get()); } + + template + inline bool + operator<=(const shared_ptr<_Tp1>& __a, + const shared_ptr<_Tp2>& __b) noexcept + { return !(__b < __a); } + + template + inline bool + operator<=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept + { return !(nullptr < __a); } + + template + inline bool + operator<=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept + { return !(__a < nullptr); } + + template + inline bool + operator>(const shared_ptr<_Tp1>& __a, + const shared_ptr<_Tp2>& __b) noexcept + { return (__b < __a); } + + template + inline bool + operator>(const shared_ptr<_Tp>& __a, nullptr_t) noexcept + { return std::less<_Tp*>()(nullptr, __a.get()); } + + template + inline bool + operator>(nullptr_t, const shared_ptr<_Tp>& __a) noexcept + { return std::less<_Tp*>()(__a.get(), nullptr); } + + template + inline bool + operator>=(const shared_ptr<_Tp1>& __a, + const shared_ptr<_Tp2>& __b) noexcept + { return !(__a < __b); } + + template + inline bool + operator>=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept + { return !(__a < nullptr); } + + template + inline bool + operator>=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept + { return !(nullptr < __a); } template struct less> : public _Sp_less> diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index 72bc4f04633..937e4f42784 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -1051,40 +1051,101 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template inline bool operator==(const __shared_ptr<_Tp1, _Lp>& __a, - const __shared_ptr<_Tp2, _Lp>& __b) + const __shared_ptr<_Tp2, _Lp>& __b) noexcept { return __a.get() == __b.get(); } template inline bool - operator==(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) - { return __a.get() == nullptr; } + operator==(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept + { return !__a; } template inline bool - operator==(nullptr_t, const __shared_ptr<_Tp, _Lp>& __b) - { return nullptr == __b.get(); } + operator==(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept + { return !__a; } template inline bool operator!=(const __shared_ptr<_Tp1, _Lp>& __a, - const __shared_ptr<_Tp2, _Lp>& __b) + const __shared_ptr<_Tp2, _Lp>& __b) noexcept { return __a.get() != __b.get(); } template inline bool - operator!=(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) - { return __a.get() != nullptr; } + operator!=(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept + { return (bool)__a; } template inline bool - operator!=(nullptr_t, const __shared_ptr<_Tp, _Lp>& __b) - { return nullptr != __b.get(); } + operator!=(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept + { return (bool)__a; } template inline bool operator<(const __shared_ptr<_Tp1, _Lp>& __a, - const __shared_ptr<_Tp2, _Lp>& __b) - { return __a.get() < __b.get(); } + const __shared_ptr<_Tp2, _Lp>& __b) noexcept + { + typedef typename std::common_type<_Tp1*, _Tp2*>::type _CT; + return std::less<_CT>()(__a.get(), __b.get()); + } + + template + inline bool + operator<(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept + { return std::less<_Tp*>()(__a.get(), nullptr); } + + template + inline bool + operator<(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept + { return std::less<_Tp*>()(nullptr, __a.get()); } + + template + inline bool + operator<=(const __shared_ptr<_Tp1, _Lp>& __a, + const __shared_ptr<_Tp2, _Lp>& __b) noexcept + { return !(__b < __a); } + + template + inline bool + operator<=(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept + { return !(nullptr < __a); } + + template + inline bool + operator<=(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept + { return !(__a < nullptr); } + + template + inline bool + operator>(const __shared_ptr<_Tp1, _Lp>& __a, + const __shared_ptr<_Tp2, _Lp>& __b) noexcept + { return (__b < __a); } + + template + inline bool + operator>(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept + { return std::less<_Tp*>()(nullptr, __a.get()); } + + template + inline bool + operator>(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept + { return std::less<_Tp*>()(__a.get(), nullptr); } + + template + inline bool + operator>=(const __shared_ptr<_Tp1, _Lp>& __a, + const __shared_ptr<_Tp2, _Lp>& __b) noexcept + { return !(__a < __b); } + + template + inline bool + operator>=(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept + { return !(__a < nullptr); } + + template + inline bool + operator>=(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept + { return !(nullptr < __a); } template struct _Sp_less : public binary_function<_Sp, _Sp, bool> diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h index 5e8ab90ce12..1afc75bcb3f 100644 --- a/libstdc++-v3/include/bits/unique_ptr.h +++ b/libstdc++-v3/include/bits/unique_ptr.h @@ -435,58 +435,107 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template inline bool - operator==(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) - { return __x.get() == nullptr; } + operator==(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept + { return !__x; } template inline bool - operator==(nullptr_t, const unique_ptr<_Tp, _Dp>& __y) - { return nullptr == __y.get(); } + operator==(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept + { return !__x; } template inline bool operator!=(const unique_ptr<_Tp, _Dp>& __x, const unique_ptr<_Up, _Ep>& __y) - { return !(__x.get() == __y.get()); } + { return __x.get() != __y.get(); } template inline bool - operator!=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) - { return __x.get() != nullptr; } + operator!=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept + { return (bool)__x; } template inline bool - operator!=(nullptr_t, const unique_ptr<_Tp, _Dp>& __y) - { return nullptr != __y.get(); } + operator!=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept + { return (bool)__x; } template inline bool operator<(const unique_ptr<_Tp, _Dp>& __x, const unique_ptr<_Up, _Ep>& __y) - { return __x.get() < __y.get(); } + { + typedef typename + std::common_type::pointer, + typename unique_ptr<_Up, _Ep>::pointer>::type _CT; + return std::less<_CT>()(__x.get(), __y.get()); + } + + template + inline bool + operator<(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) + { return std::less::pointer>()(__x.get(), + nullptr); } + + template + inline bool + operator<(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) + { return std::less::pointer>()(nullptr, + __x.get()); } template inline bool operator<=(const unique_ptr<_Tp, _Dp>& __x, const unique_ptr<_Up, _Ep>& __y) - { return !(__y.get() < __x.get()); } + { return !(__y < __x); } + + template + inline bool + operator<=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) + { return !(nullptr < __x); } + + template + inline bool + operator<=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) + { return !(__x < nullptr); } template inline bool operator>(const unique_ptr<_Tp, _Dp>& __x, const unique_ptr<_Up, _Ep>& __y) - { return __y.get() < __x.get(); } + { return (__y < __x); } + + template + inline bool + operator>(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) + { return std::less::pointer>()(nullptr, + __x.get()); } + + template + inline bool + operator>(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) + { return std::less::pointer>()(__x.get(), + nullptr); } template inline bool operator>=(const unique_ptr<_Tp, _Dp>& __x, const unique_ptr<_Up, _Ep>& __y) - { return !(__x.get() < __y.get()); } + { return !(__x < __y); } + + template + inline bool + operator>=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) + { return !(__x < nullptr); } + + template + inline bool + operator>=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) + { return !(nullptr < __x); } /// std::hash specialization for unique_ptr. template diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/comparison/dr1401.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/comparison/dr1401.cc new file mode 100644 index 00000000000..45f9b33e38e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/comparison/dr1401.cc @@ -0,0 +1,65 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2011 Free Software Foundation +// +// 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 +// . + +// 20.7.2.2 Class template shared_ptr [util.smartptr.shared] + +#include + +// DR 1401 +void test01() +{ + std::shared_ptr ptr1, ptr2; + if (ptr1 == ptr2) + { } + if (ptr1 == nullptr) + { } + if (nullptr == ptr1) + { } + if (ptr1 != ptr2) + { } + if (ptr1 != nullptr) + { } + if (nullptr != ptr1) + { } + if (ptr1 < ptr2) + { } + if (ptr1 < nullptr) + { } + if (nullptr < ptr1) + { } + if (ptr1 <= ptr2) + { } + if (ptr1 <= nullptr) + { } + if (nullptr <= ptr1) + { } + if (ptr1 > ptr2) + { } + if (ptr1 > nullptr) + { } + if (nullptr > ptr1) + { } + if (ptr1 >= ptr2) + { } + if (ptr1 >= nullptr) + { } + if (nullptr >= ptr1) + { } +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/comparison/dr1401.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/comparison/dr1401.cc new file mode 100644 index 00000000000..fb3b352a9ca --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/comparison/dr1401.cc @@ -0,0 +1,65 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2011 Free Software Foundation +// +// 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 +// . + +// 20.7.1 Class template unique_ptr [unique.ptr] + +#include + +// DR 1401 +void test01() +{ + std::unique_ptr ptr1, ptr2; + if (ptr1 == ptr2) + { } + if (ptr1 == nullptr) + { } + if (nullptr == ptr1) + { } + if (ptr1 != ptr2) + { } + if (ptr1 != nullptr) + { } + if (nullptr != ptr1) + { } + if (ptr1 < ptr2) + { } + if (ptr1 < nullptr) + { } + if (nullptr < ptr1) + { } + if (ptr1 <= ptr2) + { } + if (ptr1 <= nullptr) + { } + if (nullptr <= ptr1) + { } + if (ptr1 > ptr2) + { } + if (ptr1 > nullptr) + { } + if (nullptr > ptr1) + { } + if (ptr1 >= ptr2) + { } + if (ptr1 >= nullptr) + { } + if (nullptr >= ptr1) + { } +} diff --git a/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc b/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc index 28c8797b9ca..5990cfd4e1d 100644 --- a/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc +++ b/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc @@ -42,12 +42,18 @@ main() return 0; } -// { dg-warning "note" "" { target *-*-* } 354 } +// { dg-warning "note" "" { target *-*-* } 370 } +// { dg-warning "note" "" { target *-*-* } 365 } +// { dg-warning "note" "" { target *-*-* } 357 } +// { dg-warning "note" "" { target *-*-* } 1099 } +// { dg-warning "note" "" { target *-*-* } 1094 } // { dg-warning "note" "" { target *-*-* } 1086 } +// { dg-warning "note" "" { target *-*-* } 483 } +// { dg-warning "note" "" { target *-*-* } 477 } // { dg-warning "note" "" { target *-*-* } 467 } // { dg-warning "note" "" { target *-*-* } 587 } -// { dg-warning "note" "" { target *-*-* } 1050 } // { dg-warning "note" "" { target *-*-* } 1056 } +// { dg-warning "note" "" { target *-*-* } 1050 } // { dg-warning "note" "" { target *-*-* } 342 } // { dg-warning "note" "" { target *-*-* } 292 } // { dg-warning "note" "" { target *-*-* } 207 }