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
+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
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;
// 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; }
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&
#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__));
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
--- /dev/null
+// { 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;
+}
--- /dev/null
+// { 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" }
+}
+