diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 2033e19bbbb02c3c11e7eeafe2501e39c9a9545f..44a1662e63ea659ddd4df0724ef0fa7731acaf95 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -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 diff --git a/libstdc++-v3/libsupc++/eh_ptr.cc b/libstdc++-v3/libsupc++/eh_ptr.cc index 8a0167d75103e0bd1bc6eaca3cc29c247b9bc0c0..abe59a214be6df4be17e3156a8e3b12b996b5bf3 100644 --- a/libstdc++-v3/libsupc++/eh_ptr.cc +++ b/libstdc++-v3/libsupc++/eh_ptr.cc @@ -101,10 +101,6 @@ std::__exception_ptr::exception_ptr::_M_get() const throw() { return _M_exception_object; } -void -std::__exception_ptr::exception_ptr::_M_safe_bool_dummy() throw () { } - - void std::__exception_ptr::exception_ptr::swap(exception_ptr &other) throw() { @@ -114,6 +110,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() diff --git a/libstdc++-v3/libsupc++/exception_ptr.h b/libstdc++-v3/libsupc++/exception_ptr.h index f3f0819b1c6215d70ce5f5d0505e43e11ccc813e..4ccb4fb2d6e652581898ee5dd220fa14c7894f2f 100644 --- a/libstdc++-v3/libsupc++/exception_ptr.h +++ b/libstdc++-v3/libsupc++/exception_ptr.h @@ -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 index 0000000000000000000000000000000000000000..36e6375d9a93892c86bfbb32f9df42baf13cf394 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/requirements.cc @@ -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 index 0000000000000000000000000000000000000000..b897b506dfe3236678578fae72f5ede5057ec637 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/requirements_neg.cc @@ -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" } +} +