OSDN Git Service

2010-06-06 Jonathan Wakely <jwakely.gcc@gmail.com>
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 6 Jun 2010 13:27:23 +0000 (13:27 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 6 Jun 2010 13:27:23 +0000 (13:27 +0000)
PR libstdc++/40296
* libsupc++/exception_ptr.h (exception_ptr::exception_ptr): Replace
__safe_bool constructor with nullptr_t constructor in C++0x mode.
(exception_ptr::operator bool): Add explicit conversion to bool.
(swap(exception_ptr&, exception_ptr&)): Add.
(exception_ptr::_M_safe_bool_dummy): Only declare for old ABI.
* libsupc++/eh_ptr.cc (exception_ptr::_M_safe_bool_dummy): Move
next to other functions retained for ABI compatibility.
* testsuite/18_support/exception_ptr/requirements.cc: New.
* testsuite/18_support/exception_ptr/requirements_neg.cc: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@160340 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/libsupc++/eh_ptr.cc
libstdc++-v3/libsupc++/exception_ptr.h
libstdc++-v3/testsuite/18_support/exception_ptr/requirements.cc [new file with mode: 0644]
libstdc++-v3/testsuite/18_support/exception_ptr/requirements_neg.cc [new file with mode: 0644]

index 2033e19..44a1662 100644 (file)
@@ -1,3 +1,16 @@
+2010-06-06  Jonathan Wakely  <jwakely.gcc@gmail.com>
+
+       PR libstdc++/40296
+       * libsupc++/exception_ptr.h (exception_ptr::exception_ptr): Replace
+       __safe_bool constructor with nullptr_t constructor in C++0x mode.
+       (exception_ptr::operator bool): Add explicit conversion to bool.
+       (swap(exception_ptr&, exception_ptr&)): Add.
+       (exception_ptr::_M_safe_bool_dummy): Only declare for old ABI.
+       * libsupc++/eh_ptr.cc (exception_ptr::_M_safe_bool_dummy): Move
+       next to other functions retained for ABI compatibility.
+       * testsuite/18_support/exception_ptr/requirements.cc: New.
+       * testsuite/18_support/exception_ptr/requirements_neg.cc: New.
+
 2010-06-05  Jonathan Wakely  <jwakely.gcc@gmail.com>
 
        * include/bits/shared_ptr_base.h (_Sp_counted_ptr::_M_dispose): Make
index 8a0167d..abe59a2 100644 (file)
@@ -102,10 +102,6 @@ std::__exception_ptr::exception_ptr::_M_get() const throw()
 
 
 void
-std::__exception_ptr::exception_ptr::_M_safe_bool_dummy() throw () { }
-
-
-void
 std::__exception_ptr::exception_ptr::swap(exception_ptr &other) throw()
 {
   void *tmp = _M_exception_object;
@@ -115,6 +111,11 @@ std::__exception_ptr::exception_ptr::swap(exception_ptr &other) throw()
 
 
 // Retained for compatibility with CXXABI_1.3.
+void
+std::__exception_ptr::exception_ptr::_M_safe_bool_dummy() throw () { }
+
+
+// Retained for compatibility with CXXABI_1.3.
 bool
 std::__exception_ptr::exception_ptr::operator!() const throw()
 { return _M_exception_object == 0; }
index f3f0819..4ccb4fb 100644 (file)
@@ -81,25 +81,27 @@ namespace std
 
       void *_M_get() const throw() __attribute__ ((__pure__));
 
-      void _M_safe_bool_dummy() throw() __attribute__ ((__const__));
-
       friend exception_ptr std::current_exception() throw();
       friend void std::rethrow_exception(exception_ptr);
 
     public:
       exception_ptr() throw();
 
-      typedef void (exception_ptr::*__safe_bool)();
-
-      // For construction from nullptr or 0.
-      exception_ptr(__safe_bool) throw();
-
       exception_ptr(const exception_ptr&) throw();
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
+      exception_ptr(nullptr_t) throw()
+      : _M_exception_object(0)
+      { }
+
       exception_ptr(exception_ptr&& __o) throw()
       : _M_exception_object(__o._M_exception_object)
       { __o._M_exception_object = 0; }
+#else
+      typedef void (exception_ptr::*__safe_bool)();
+
+      // For construction from nullptr or 0.
+      exception_ptr(__safe_bool) throw();
 #endif
 
       exception_ptr& 
@@ -121,10 +123,16 @@ namespace std
 
 #ifdef _GLIBCXX_EH_PTR_COMPAT
       // Retained for compatibility with CXXABI_1.3.
+      void _M_safe_bool_dummy() throw() __attribute__ ((__const__));
       bool operator!() const throw() __attribute__ ((__pure__));
       operator __safe_bool() const throw();
 #endif
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      explicit operator bool() const
+      { return _M_exception_object; }
+#endif
+
       friend bool 
       operator==(const exception_ptr&, const exception_ptr&) throw() 
       __attribute__ ((__pure__));
@@ -140,6 +148,11 @@ namespace std
     bool 
     operator!=(const exception_ptr&, const exception_ptr&) throw() 
     __attribute__ ((__pure__));
+
+    inline void
+    swap(exception_ptr& __lhs, exception_ptr& __rhs)
+    { __lhs.swap(__rhs); }
+
   } // namespace __exception_ptr
 
 
diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/requirements.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/requirements.cc
new file mode 100644 (file)
index 0000000..36e6375
--- /dev/null
@@ -0,0 +1,60 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2010 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 <exception>
+#include <testsuite_hooks.h>
+
+// test NullablePointer requirements
+void test01()
+{
+  std::exception_ptr p1;        // DefaultConstructible
+  std::exception_ptr p2(p1);    // CopyConstructible
+  p1 = p2;                      // CopyAssignable
+  VERIFY( p1 == p2 );           // EqualityComparable
+  VERIFY( !bool(p1) );          // contextually convertible to bool
+  swap(p1, p2);                 // Swappable
+
+  // Table 39 expressions
+  std::exception_ptr p3 = nullptr;
+  std::exception_ptr p4(nullptr);
+  VERIFY( std::exception_ptr() == nullptr );
+  p4 = nullptr;
+  VERIFY( p4 == nullptr );
+  VERIFY( nullptr == p4 );
+  VERIFY( (p4 != nullptr) == !(p4 == nullptr) );
+  VERIFY( (nullptr != p4) == !(p4 == nullptr) );
+
+  std::exception_ptr p5{};      // value initialized ...
+  VERIFY( p5 == nullptr );      // ... is equivalent to null
+}
+
+// additional exception_ptr requirements
+void test02()
+{
+  std::exception_ptr p1;
+  VERIFY( p1 == nullptr );
+}
+
+int main()
+{
+  test01();
+  test02();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/requirements_neg.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/requirements_neg.cc
new file mode 100644 (file)
index 0000000..b897b50
--- /dev/null
@@ -0,0 +1,33 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2010 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 <exception>
+
+// test implicit conversions
+void test01()
+{
+  std::exception_ptr p;
+
+  int   __attribute__((unused)) i = p; // { dg-error "cannot convert" }
+  bool  __attribute__((unused)) b = p; // { dg-error "cannot convert" }
+  void* __attribute__((unused)) v = p; // { dg-error "cannot convert" }
+}
+