diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 9dec9f9dc6e8a7b4634ef228e0ac7461e06047d7..388b3cc7fc990b3e257d113743d5ca15709258a8 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2010-03-19 Rodolfo Lima <rodolfo@rodsoft.org> + + * include/bits/shared_ptr.h (shared_ptr(unique_ptr&&), + shared_ptr(auto_ptr&&)): Remove explicit specifier (as per DR 925). + * include/bits/shared_ptr_base.h: Likewise. + * testsuite/20_util/shared_ptr/creation/dr925.cc: New. + 2010-03-19 Paolo Carlini <paolo.carlini@oracle.com> * include/bits/random.tcc: Minor formatting changes. diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index b204699db20c2aa12e9664c5fd552bd5e7d32ba0..5e1960012c9ef7777dab1a80b713b9a8208f4977 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -204,13 +204,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std) #if _GLIBCXX_DEPRECATED template<typename _Tp1> - explicit shared_ptr(std::auto_ptr<_Tp1>&& __r) : __shared_ptr<_Tp>(std::move(__r)) { } #endif template<typename _Tp1, typename _Del> - explicit shared_ptr(std::unique_ptr<_Tp1, _Del>&& __r) + shared_ptr(std::unique_ptr<_Tp1, _Del>&& __r) : __shared_ptr<_Tp>(std::move(__r)) { } template<typename _Tp1> diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index 9d36faf7cc7970f5873b33768c037db8956789e1..1999f36023bbed0fccd9a0be9e3a258e1c9be26b 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -316,14 +316,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std) #if _GLIBCXX_DEPRECATED // Special case for auto_ptr<_Tp> to provide the strong guarantee. template<typename _Tp> - explicit __shared_count(std::auto_ptr<_Tp>&& __r) + __shared_count(std::auto_ptr<_Tp>&& __r) : _M_pi(new _Sp_counted_ptr<_Tp*, _Lp>(__r.get())) { __r.release(); } #endif // Special case for unique_ptr<_Tp,_Del> to provide the strong guarantee. template<typename _Tp, typename _Del> - explicit __shared_count(std::unique_ptr<_Tp, _Del>&& __r) + __shared_count(std::unique_ptr<_Tp, _Del>&& __r) : _M_pi(_S_create_from_up(std::move(__r))) { __r.release(); } @@ -608,7 +608,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // If an exception is thrown this constructor has no effect. template<typename _Tp1, typename _Del> - explicit __shared_ptr(std::unique_ptr<_Tp1, _Del>&& __r) + __shared_ptr(std::unique_ptr<_Tp1, _Del>&& __r) : _M_ptr(__r.get()), _M_refcount() { __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) @@ -620,7 +620,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) #if _GLIBCXX_DEPRECATED // Postcondition: use_count() == 1 and __r.get() == 0 template<typename _Tp1> - explicit __shared_ptr(std::auto_ptr<_Tp1>&& __r) + __shared_ptr(std::auto_ptr<_Tp1>&& __r) : _M_ptr(__r.get()), _M_refcount() { __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/creation/dr925.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/dr925.cc new file mode 100644 index 0000000000000000000000000000000000000000..db176650e0b24e5a1342c9e54602666fecc0d8e1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/dr925.cc @@ -0,0 +1,90 @@ +// { dg-options "-std=gnu++0x -Wno-deprecated" } + +// Copyright (C) 2010 Free Software Foundation +// +// 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/>. + +// 20.9.11.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ +}; + +std::unique_ptr<A> +create_unique_ptr() +{ + return std::unique_ptr<A>(new A()); +} + +std::auto_ptr<A> +create_auto_ptr() +{ + return std::auto_ptr<A>(new A()); +} + +void +process(std::shared_ptr<A> a) +{ + bool test __attribute__((unused)) = true; + + VERIFY( a.get() != 0 ); + VERIFY( a.use_count() == 1 ); +} + +// 20.9.11.2.1 shared_ptr creation [util.smartptr.shared.const] + +// Implicit conversion of auto_ptr to shared_ptr is allowed + +void +test01() +{ + process(create_auto_ptr()); +} + +void +test02() +{ + std::auto_ptr<A> a = create_auto_ptr(); + process(std::move(a)); +} + +// Implicit conversion of unique_ptr to shared_ptr is allowed + +void +test03() +{ + process(create_unique_ptr()); +} + +void +test04() +{ + std::unique_ptr<A> a = create_unique_ptr(); + process(std::move(a)); +} + +int +main() +{ + test01(); + test02(); + test03(); + test04(); + return 0; +}