re PR libstdc++/40296 ([C++0x] std::exception_ptr comparisons)

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.

From-SVN: r160340
This commit is contained in:
Jonathan Wakely 2010-06-06 13:27:23 +00:00 committed by Jonathan Wakely
parent 346967d1cf
commit b4e77f9b76
5 changed files with 133 additions and 13 deletions

View 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

View File

@ -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()

View 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();
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();
exception_ptr(const exception_ptr&) throw();
#ifdef __GXX_EXPERIMENTAL_CXX0X__
exception_ptr(exception_ptr&& __o) throw()
: _M_exception_object(__o._M_exception_object)
{ __o._M_exception_object = 0; }
#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

View File

@ -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;
}

View File

@ -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" }
}