Commit be9d3d73 by Paolo Carlini Committed by Paolo Carlini

shared_ptr.h (shared_ptr<>::__shared_ptr(), [...]): Add constexpr specifier.

2010-11-05  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/bits/shared_ptr.h (shared_ptr<>::__shared_ptr(),
	shared_ptr<>::shared_ptr(nullptr_t), weak_ptr<>::weak_ptr(),
	enable_shared_from_this::enable_shared_from_this()): Add constexpr
	specifier.
	* include/bits/shared_ptr_base.h (__shared_count::__shared_count(),
	__shared_count::__shared_count(), __shared_ptr<>::__shared_ptr(),
	__shared_ptr<>::__shared_ptr(nullptr_t), __weak_ptr<>::__weak_ptr(),
	__enable_shared_from_this::__enable_shared_from_this()): Likewise.
	* include/bits/unique_ptr.h (default_delete,
	unique_ptr<>::unique_ptr(), unique_ptr<>::unique_ptr(nullptr_t)):
	Likewise.
	* testsuite/20_util/default_delete/cons/constexpr.cc: Do not xfail.
	* testsuite/20_util/shared_ptr/cons/constexpr.cc: Remove, the test
	cannot work for a non-literal type like std::shared_ptr.
	* testsuite/20_util/weak_ptr/cons/constexpr.cc: Likewise.
	* testsuite/util/testsuite_common_types.h: Add comments.
	* testsuite/20_util/unique_ptr/cons/constexpr.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/43820.cc: Adjust dg-error line
	numbers.
	* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Likewise.

From-SVN: r166386
parent a75de692
2010-11-05 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (shared_ptr<>::__shared_ptr(),
shared_ptr<>::shared_ptr(nullptr_t), weak_ptr<>::weak_ptr(),
enable_shared_from_this::enable_shared_from_this()): Add constexpr
specifier.
* include/bits/shared_ptr_base.h (__shared_count::__shared_count(),
__shared_count::__shared_count(), __shared_ptr<>::__shared_ptr(),
__shared_ptr<>::__shared_ptr(nullptr_t), __weak_ptr<>::__weak_ptr(),
__enable_shared_from_this::__enable_shared_from_this()): Likewise.
* include/bits/unique_ptr.h (default_delete,
unique_ptr<>::unique_ptr(), unique_ptr<>::unique_ptr(nullptr_t)):
Likewise.
* testsuite/20_util/default_delete/cons/constexpr.cc: Do not xfail.
* testsuite/20_util/shared_ptr/cons/constexpr.cc: Remove, the test
cannot work for a non-literal type like std::shared_ptr.
* testsuite/20_util/weak_ptr/cons/constexpr.cc: Likewise.
* testsuite/util/testsuite_common_types.h: Add comments.
* testsuite/20_util/unique_ptr/cons/constexpr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/43820.cc: Adjust dg-error line
numbers.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Likewise.
2010-11-05 Benjamin Kosnik <bkoz@redhat.com> 2010-11-05 Benjamin Kosnik <bkoz@redhat.com>
* doc/doxygen/user.cfg.in: Remove tr1_impl headers. * doc/doxygen/user.cfg.in: Remove tr1_impl headers.
......
...@@ -95,7 +95,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -95,7 +95,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* @brief Construct an empty %shared_ptr. * @brief Construct an empty %shared_ptr.
* @post use_count()==0 && get()==0 * @post use_count()==0 && get()==0
*/ */
shared_ptr() : __shared_ptr<_Tp>() { } constexpr shared_ptr()
: __shared_ptr<_Tp>() { }
/** /**
* @brief Construct a %shared_ptr that owns the pointer @a __p. * @brief Construct a %shared_ptr that owns the pointer @a __p.
...@@ -104,7 +105,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -104,7 +105,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* @throw std::bad_alloc, in which case @c delete @a __p is called. * @throw std::bad_alloc, in which case @c delete @a __p is called.
*/ */
template<typename _Tp1> template<typename _Tp1>
explicit shared_ptr(_Tp1* __p) : __shared_ptr<_Tp>(__p) { } explicit shared_ptr(_Tp1* __p)
: __shared_ptr<_Tp>(__p) { }
/** /**
* @brief Construct a %shared_ptr that owns the pointer @a __p * @brief Construct a %shared_ptr that owns the pointer @a __p
...@@ -256,7 +258,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -256,7 +258,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* @param __p A null pointer constant. * @param __p A null pointer constant.
* @post use_count() == 0 && get() == nullptr * @post use_count() == 0 && get() == nullptr
*/ */
shared_ptr(nullptr_t __p) : __shared_ptr<_Tp>(__p) { } constexpr shared_ptr(nullptr_t __p)
: __shared_ptr<_Tp>(__p) { }
template<typename _Tp1> template<typename _Tp1>
shared_ptr& shared_ptr&
...@@ -387,7 +390,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -387,7 +390,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
class weak_ptr : public __weak_ptr<_Tp> class weak_ptr : public __weak_ptr<_Tp>
{ {
public: public:
weak_ptr() : __weak_ptr<_Tp>() { } constexpr weak_ptr()
: __weak_ptr<_Tp>() { }
template<typename _Tp1, typename = typename template<typename _Tp1, typename = typename
std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
...@@ -466,7 +470,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -466,7 +470,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
class enable_shared_from_this class enable_shared_from_this
{ {
protected: protected:
enable_shared_from_this() { } constexpr enable_shared_from_this() { }
enable_shared_from_this(const enable_shared_from_this&) { } enable_shared_from_this(const enable_shared_from_this&) { }
......
...@@ -443,7 +443,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -443,7 +443,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
class __shared_count class __shared_count
{ {
public: public:
__shared_count() : _M_pi(0) // nothrow constexpr __shared_count() : _M_pi(0) // nothrow
{ } { }
template<typename _Ptr> template<typename _Ptr>
...@@ -635,7 +635,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -635,7 +635,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
class __weak_count class __weak_count
{ {
public: public:
__weak_count() : _M_pi(0) // nothrow constexpr __weak_count() : _M_pi(0) // nothrow
{ } { }
__weak_count(const __shared_count<_Lp>& __r) : _M_pi(__r._M_pi) // nothrow __weak_count(const __shared_count<_Lp>& __r) : _M_pi(__r._M_pi) // nothrow
...@@ -751,11 +751,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -751,11 +751,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
public: public:
typedef _Tp element_type; typedef _Tp element_type;
__shared_ptr() : _M_ptr(0), _M_refcount() // never throws constexpr __shared_ptr()
: _M_ptr(0), _M_refcount() // never throws
{ } { }
template<typename _Tp1> template<typename _Tp1>
explicit __shared_ptr(_Tp1* __p) : _M_ptr(__p), _M_refcount(__p) explicit __shared_ptr(_Tp1* __p)
: _M_ptr(__p), _M_refcount(__p)
{ {
__glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
static_assert( sizeof(_Tp1) > 0, "incomplete type" ); static_assert( sizeof(_Tp1) > 0, "incomplete type" );
...@@ -856,7 +858,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -856,7 +858,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
#endif #endif
/* TODO: use delegating constructor */ /* TODO: use delegating constructor */
__shared_ptr(nullptr_t) : _M_ptr(0), _M_refcount() // never throws constexpr __shared_ptr(nullptr_t)
: _M_ptr(0), _M_refcount() // never throws
{ } { }
template<typename _Tp1> template<typename _Tp1>
...@@ -1163,7 +1166,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -1163,7 +1166,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
public: public:
typedef _Tp element_type; typedef _Tp element_type;
__weak_ptr() : _M_ptr(0), _M_refcount() // never throws constexpr __weak_ptr()
: _M_ptr(0), _M_refcount() // never throws
{ } { }
// Generated copy constructor, assignment, destructor are fine. // Generated copy constructor, assignment, destructor are fine.
...@@ -1324,7 +1328,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -1324,7 +1328,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
class __enable_shared_from_this class __enable_shared_from_this
{ {
protected: protected:
__enable_shared_from_this() { } constexpr __enable_shared_from_this() { }
__enable_shared_from_this(const __enable_shared_from_this&) { } __enable_shared_from_this(const __enable_shared_from_this&) { }
......
...@@ -46,20 +46,20 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -46,20 +46,20 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
/// Primary template, default_delete. /// Primary template, default_delete.
template<typename _Tp> template<typename _Tp>
struct default_delete struct default_delete
{ {
default_delete() { } constexpr default_delete() { }
template<typename _Up, typename = typename template<typename _Up, typename = typename
std::enable_if<std::is_convertible<_Up*, _Tp*>::value>::type> std::enable_if<std::is_convertible<_Up*, _Tp*>::value>::type>
default_delete(const default_delete<_Up>&) { } default_delete(const default_delete<_Up>&) { }
void void
operator()(_Tp* __ptr) const operator()(_Tp* __ptr) const
{ {
static_assert(sizeof(_Tp)>0, static_assert(sizeof(_Tp)>0,
"can't delete pointer to incomplete type"); "can't delete pointer to incomplete type");
delete __ptr; delete __ptr;
} }
}; };
// _GLIBCXX_RESOLVE_LIB_DEFECTS // _GLIBCXX_RESOLVE_LIB_DEFECTS
...@@ -68,6 +68,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -68,6 +68,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
template<typename _Tp> template<typename _Tp>
struct default_delete<_Tp[]> struct default_delete<_Tp[]>
{ {
constexpr default_delete() { }
void void
operator()(_Tp* __ptr) const operator()(_Tp* __ptr) const
{ {
...@@ -108,8 +110,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -108,8 +110,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
"constructed with null function pointer deleter"); "constructed with null function pointer deleter");
// Constructors. // Constructors.
unique_ptr() constexpr unique_ptr()
: _M_t(pointer(), deleter_type()) : _M_t()
{ } { }
explicit explicit
...@@ -129,7 +131,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -129,7 +131,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{ static_assert(!std::is_reference<deleter_type>::value, { static_assert(!std::is_reference<deleter_type>::value,
"rvalue deleter bound to reference"); } "rvalue deleter bound to reference"); }
unique_ptr(nullptr_t) constexpr unique_ptr(nullptr_t)
: _M_t(pointer(), deleter_type()) : _M_t(pointer(), deleter_type())
{ } { }
...@@ -271,7 +273,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -271,7 +273,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
"constructed with null function pointer deleter"); "constructed with null function pointer deleter");
// Constructors. // Constructors.
unique_ptr() constexpr unique_ptr()
: _M_t(pointer(), deleter_type()) : _M_t(pointer(), deleter_type())
{ } { }
...@@ -292,7 +294,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -292,7 +294,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
"rvalue deleter bound to reference"); } "rvalue deleter bound to reference"); }
/* TODO: use delegating constructor */ /* TODO: use delegating constructor */
unique_ptr(nullptr_t) constexpr unique_ptr(nullptr_t)
: _M_t(pointer(), deleter_type()) : _M_t(pointer(), deleter_type())
{ } { }
......
// { dg-do compile { xfail *-*-* } } // { dg-do compile }
// { dg-options "-std=gnu++0x" } // { dg-options "-std=gnu++0x" }
// Copyright (C) 2010 Free Software Foundation, Inc. // Copyright (C) 2010 Free Software Foundation, Inc.
...@@ -24,6 +24,6 @@ ...@@ -24,6 +24,6 @@
int main() int main()
{ {
__gnu_test::constexpr_default_constructible test; __gnu_test::constexpr_default_constructible test;
test.operator()<std::default_delete<int>>(); // { dg-excess-errors "" } test.operator()<std::default_delete<int>>();
return 0; return 0;
} }
...@@ -32,9 +32,9 @@ void test01() ...@@ -32,9 +32,9 @@ void test01()
{ {
X* px = 0; X* px = 0;
std::shared_ptr<X> p1(px); // { dg-error "here" } std::shared_ptr<X> p1(px); // { dg-error "here" }
// { dg-error "incomplete" "" { target *-*-* } 762 } // { dg-error "incomplete" "" { target *-*-* } 764 }
std::shared_ptr<X> p9(ap()); // { dg-error "here" } std::shared_ptr<X> p9(ap()); // { dg-error "here" }
// { dg-error "incomplete" "" { target *-*-* } 854 } // { dg-error "incomplete" "" { target *-*-* } 856 }
} }
// { dg-do compile { xfail *-*-* } }
// { dg-options "-std=gnu++0x" }
// 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 <memory>
#include <testsuite_common_types.h>
int main()
{
__gnu_test::constexpr_default_constructible test1;
test1.operator()<std::shared_ptr<int>>(); // { dg-excess-errors "" }
__gnu_test::constexpr_single_value_constructible test2;
test2.operator()<std::shared_ptr<int>, std::nullptr_t>(); // { dg-excess-errors "" }
return 0;
}
// { dg-do compile { xfail *-*-* } }
// { dg-options "-std=gnu++0x" }
// 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 <memory>
#include <testsuite_common_types.h>
int main()
{
__gnu_test::constexpr_default_constructible test1;
test1.operator()<std::unique_ptr<int>>(); // { dg-excess-errors "" }
__gnu_test::constexpr_single_value_constructible test2;
test2.operator()<std::unique_ptr<int>, std::nullptr_t>(); // { dg-excess-errors "" }
return 0;
}
...@@ -41,9 +41,9 @@ main() ...@@ -41,9 +41,9 @@ main()
return 0; return 0;
} }
// { dg-warning "note" "" { target *-*-* } 347 } // { dg-warning "note" "" { target *-*-* } 350 }
// { dg-warning "note" "" { target *-*-* } 1079 } // { dg-warning "note" "" { target *-*-* } 1082 }
// { dg-warning "note" "" { target *-*-* } 465 } // { dg-warning "note" "" { target *-*-* } 467 }
// { dg-warning "note" "" { target *-*-* } 580 } // { dg-warning "note" "" { target *-*-* } 580 }
// { dg-warning "note" "" { target *-*-* } 1027 } // { dg-warning "note" "" { target *-*-* } 1027 }
// { dg-warning "note" "" { target *-*-* } 340 } // { dg-warning "note" "" { target *-*-* } 340 }
......
// { dg-do compile { xfail *-*-* } }
// { dg-options "-std=gnu++0x" }
// 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 <memory>
#include <testsuite_common_types.h>
int main()
{
__gnu_test::constexpr_default_constructible test;
test.operator()<std::weak_ptr<int>>(); // { dg-excess-errors "" }
// test.operator()<std::__weak_ptr<int>>();
// test.operator()<std::__weak_count<__gnu_cxx::__default_lock_policy>>();
// test.operator()<std::_Sp_counted_base<__gnu_cxx::__default_lock_policy>>();
return 0;
}
...@@ -615,6 +615,7 @@ namespace __gnu_test ...@@ -615,6 +615,7 @@ namespace __gnu_test
// Generator to test default constructor. // Generator to test default constructor.
struct constexpr_default_constructible struct constexpr_default_constructible
{ {
// NB: _Tp must be a literal type.
template<typename _Tp> template<typename _Tp>
void void
operator()() operator()()
...@@ -633,6 +634,7 @@ namespace __gnu_test ...@@ -633,6 +634,7 @@ namespace __gnu_test
struct constexpr_single_value_constructible struct constexpr_single_value_constructible
{ {
// NB: _Tbasetype and _Ttesttype must be literal types.
template<typename _Ttesttype, typename _Tbasetype> template<typename _Ttesttype, typename _Tbasetype>
void void
operator()() operator()()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment