diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 9dec9f9dc6e..388b3cc7fc9 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2010-03-19 Rodolfo Lima + + * 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 * 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 b204699db20..5e1960012c9 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 - explicit shared_ptr(std::auto_ptr<_Tp1>&& __r) : __shared_ptr<_Tp>(std::move(__r)) { } #endif template - explicit shared_ptr(std::unique_ptr<_Tp1, _Del>&& __r) + shared_ptr(std::unique_ptr<_Tp1, _Del>&& __r) : __shared_ptr<_Tp>(std::move(__r)) { } template diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index 9d36faf7cc7..1999f36023b 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 - 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 - 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 - 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 - 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 00000000000..db176650e0b --- /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 +// . + +// 20.9.11.2 Template class shared_ptr [util.smartptr.shared] + +#include +#include + +struct A +{ +}; + +std::unique_ptr +create_unique_ptr() +{ + return std::unique_ptr(new A()); +} + +std::auto_ptr +create_auto_ptr() +{ + return std::auto_ptr(new A()); +} + +void +process(std::shared_ptr 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 = 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 = create_unique_ptr(); + process(std::move(a)); +} + +int +main() +{ + test01(); + test02(); + test03(); + test04(); + return 0; +}