]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/42925 ([GB 99] Not possible to compare unique_ptr with 0)
authorPaolo Carlini <paolo.carlini@oracle.com>
Wed, 11 Aug 2010 08:49:47 +0000 (08:49 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 11 Aug 2010 08:49:47 +0000 (08:49 +0000)
2010-08-11  Paolo Carlini  <paolo.carlini@oracle.com>

PR libstdc++/42925
* include/bits/unique_ptr.h (operator==(const unique_ptr<>&,
nullptr_t), operator==(nullptr_t, const unique_ptr<>&),
operator!=(const unique_ptr<>&, nullptr_t),
operator!=(nullptr_t, const unique_ptr<>&)): Add.
* include/bits/shared_ptr_base.h (operator==(const __shared_ptr<>&,
nullptr_t), operator==(nullptr_t, const __shared_ptr<>&),
operator!=(const __shared_ptr<>&, nullptr_t),
operator!=(nullptr_t, const __shared_ptr<>&)): Likewise.
* include/bits/shared_ptr.h (operator==(const shared_ptr<>&,
nullptr_t), operator==(nullptr_t, const shared_ptr<>&),
operator!=(const shared_ptr<>&, nullptr_t),
operator!=(nullptr_t, const shared_ptr<>&)): Likewise.
* testsuite/20_util/unique_ptr/comparison/42925.cc: New.
* testsuite/20_util/shared_ptr/comparison/42925.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust
dg-error line numbers.

From-SVN: r163094

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/shared_ptr.h
libstdc++-v3/include/bits/shared_ptr_base.h
libstdc++-v3/include/bits/unique_ptr.h
libstdc++-v3/testsuite/20_util/shared_ptr/comparison/42925.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/unique_ptr/comparison/42925.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc

index 390bbcc1dfc0a016ef1c1cdc728485f0ea12817a..b900bf56565ff793d2bb1416b8e8922dfca1b0d5 100644 (file)
@@ -1,3 +1,23 @@
+2010-08-11  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR libstdc++/42925
+       * include/bits/unique_ptr.h (operator==(const unique_ptr<>&,
+       nullptr_t), operator==(nullptr_t, const unique_ptr<>&),
+       operator!=(const unique_ptr<>&, nullptr_t),
+       operator!=(nullptr_t, const unique_ptr<>&)): Add.
+       * include/bits/shared_ptr_base.h (operator==(const __shared_ptr<>&,
+       nullptr_t), operator==(nullptr_t, const __shared_ptr<>&),
+       operator!=(const __shared_ptr<>&, nullptr_t),
+       operator!=(nullptr_t, const __shared_ptr<>&)): Likewise.
+       * include/bits/shared_ptr.h (operator==(const shared_ptr<>&,
+       nullptr_t), operator==(nullptr_t, const shared_ptr<>&),
+       operator!=(const shared_ptr<>&, nullptr_t),
+       operator!=(nullptr_t, const shared_ptr<>&)): Likewise.
+       * testsuite/20_util/unique_ptr/comparison/42925.cc: New.
+       * testsuite/20_util/shared_ptr/comparison/42925.cc: Likewise.
+       * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust
+       dg-error line numbers.
+
 2010-08-11  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * include/bits/unique_ptr.h: Replace _Tp_Deleter -> _Dp, and
index fe79cdd1547d32d81234d5620dea3d064f38a652..2d9e6f771a61975418aaae9b1d5d2de77f23da6c 100644 (file)
@@ -317,11 +317,31 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     operator==(const shared_ptr<_Tp1>& __a, const shared_ptr<_Tp2>& __b)
     { return __a.get() == __b.get(); }
 
+  template<typename _Tp>
+    inline bool
+    operator==(const shared_ptr<_Tp>& __a, nullptr_t)
+    { return __a.get() == nullptr; }
+
+  template<typename _Tp>
+    inline bool
+    operator==(nullptr_t, const shared_ptr<_Tp>& __b)
+    { return nullptr == __b.get(); }
+
   template<typename _Tp1, typename _Tp2>
     inline bool
     operator!=(const shared_ptr<_Tp1>& __a, const shared_ptr<_Tp2>& __b)
     { return __a.get() != __b.get(); }
 
+  template<typename _Tp>
+    inline bool
+    operator!=(const shared_ptr<_Tp>& __a, nullptr_t)
+    { return __a.get() != nullptr; }
+
+  template<typename _Tp>
+    inline bool
+    operator!=(nullptr_t, const shared_ptr<_Tp>& __b)
+    { return nullptr != __b.get(); }
+
   template<typename _Tp1, typename _Tp2>
     inline bool
     operator<(const shared_ptr<_Tp1>& __a, const shared_ptr<_Tp2>& __b)
index 802d1b5b70eeac3fbe7f427a8f24bb92bf89cbcd..183c241e29bc3955e0a437018ccf12b8d0ad8e86 100644 (file)
@@ -851,12 +851,32 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
               const __shared_ptr<_Tp2, _Lp>& __b)
     { return __a.get() == __b.get(); }
 
+  template<typename _Tp, _Lock_policy _Lp>
+    inline bool
+    operator==(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t)
+    { return __a.get() == nullptr; }
+
+  template<typename _Tp, _Lock_policy _Lp>
+    inline bool
+    operator==(nullptr_t, const __shared_ptr<_Tp, _Lp>& __b)
+    { return nullptr == __b.get(); }
+
   template<typename _Tp1, typename _Tp2, _Lock_policy _Lp>
     inline bool
     operator!=(const __shared_ptr<_Tp1, _Lp>& __a,
               const __shared_ptr<_Tp2, _Lp>& __b)
     { return __a.get() != __b.get(); }
 
+  template<typename _Tp, _Lock_policy _Lp>
+    inline bool
+    operator!=(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t)
+    { return __a.get() != nullptr; }
+
+  template<typename _Tp, _Lock_policy _Lp>
+    inline bool
+    operator!=(nullptr_t, const __shared_ptr<_Tp, _Lp>& __b)
+    { return nullptr != __b.get(); }
+
   template<typename _Tp1, typename _Tp2, _Lock_policy _Lp>
     inline bool
     operator<(const __shared_ptr<_Tp1, _Lp>& __a,
index 1dfba0b825e06b667d559b4ca183fee7e6e8c7d0..d6adb1459e313ae8fdc435ce189d5c54ad4fe163 100644 (file)
@@ -101,7 +101,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     public:
       typedef typename _Pointer::type  pointer;
       typedef _Tp                       element_type;
-      typedef _Dp               deleter_type;
+      typedef _Dp                       deleter_type;
 
       // Constructors.
       unique_ptr()
@@ -432,6 +432,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
               const unique_ptr<_Up, _Ep>& __y)
     { return __x.get() == __y.get(); }
 
+  template<typename _Tp, typename _Dp>
+    inline bool
+    operator==(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
+    { return __x.get() == nullptr; }
+
+  template<typename _Tp, typename _Dp>
+    inline bool
+    operator==(nullptr_t, const unique_ptr<_Tp, _Dp>& __y)
+    { return nullptr == __y.get(); }
+
   template<typename _Tp, typename _Dp,
           typename _Up, typename _Ep>
     inline bool
@@ -439,6 +449,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
               const unique_ptr<_Up, _Ep>& __y)
     { return !(__x.get() == __y.get()); }
 
+  template<typename _Tp, typename _Dp>
+    inline bool
+    operator!=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
+    { return __x.get() != nullptr; }
+
+  template<typename _Tp, typename _Dp>
+    inline bool
+    operator!=(nullptr_t, const unique_ptr<_Tp, _Dp>& __y)
+    { return nullptr != __y.get(); }
+
   template<typename _Tp, typename _Dp,
           typename _Up, typename _Ep>
     inline bool
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/comparison/42925.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/comparison/42925.cc
new file mode 100644 (file)
index 0000000..41e09d6
--- /dev/null
@@ -0,0 +1,37 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+// Copyright (C) 2010 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
+// <http://www.gnu.org/licenses/>.
+
+// 20.9.11.2 Class template shared_ptr [util.smartptr.shared]
+
+#include <memory>
+
+// libstdc++/42925 (also see GB 99)
+void test01()
+{
+  std::shared_ptr<int> ptr;
+  if (ptr == 0)
+    { }
+  if (0 == ptr)
+    { }
+  if (ptr != 0)
+    { }
+  if (0 != ptr)
+    { }
+}
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/comparison/42925.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/comparison/42925.cc
new file mode 100644 (file)
index 0000000..e3dfad4
--- /dev/null
@@ -0,0 +1,37 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+// Copyright (C) 2010 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
+// <http://www.gnu.org/licenses/>.
+
+// 20.9.10 Class template unique_ptr [unique.ptr]
+
+#include <memory>
+
+// libstdc++/42925 (also see GB 99)
+void test01()
+{
+  std::unique_ptr<int> ptr;
+  if (ptr == 0)
+    { }
+  if (0 == ptr)
+    { }
+  if (ptr != 0)
+    { }
+  if (0 != ptr)
+    { }
+}
index ea84c7e82a9f2fb4393eb3fa24ff33180cd9fce6..f124718016eb1bc62f162ce4e732805f5e72ae7d 100644 (file)
@@ -41,9 +41,9 @@ main()
   return 0;
 }
 
-// { dg-warning "note" "" { target *-*-* } 327 }
-// { dg-warning "note" "" { target *-*-* } 446 }
-// { dg-warning "note" "" { target *-*-* } 863 }
+// { dg-warning "note" "" { target *-*-* } 347 }
+// { dg-warning "note" "" { target *-*-* } 466 }
+// { dg-warning "note" "" { target *-*-* } 883 }
 // { dg-warning "note" "" { target *-*-* } 580 }
 // { dg-warning "note" "" { target *-*-* } 1027 }
 // { dg-warning "note" "" { target *-*-* } 340 }