1// { dg-options "-std=gnu++0x -Wno-deprecated" } 2 3// Copyright (C) 2010 Free Software Foundation 4// 5// This file is part of the GNU ISO C++ Library. This library is free 6// software; you can redistribute it and/or modify it under the 7// terms of the GNU General Public License as published by the 8// Free Software Foundation; either version 3, or (at your option) 9// any later version. 10 11// This library is distributed in the hope that it will be useful, 12// but WITHOUT ANY WARRANTY; without even the implied warranty of 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14// GNU General Public License for more details. 15 16// You should have received a copy of the GNU General Public License along 17// with this library; see the file COPYING3. If not see 18// <http://www.gnu.org/licenses/>. 19 20// 20.9.11.2 Template class shared_ptr [util.smartptr.shared] 21 22#include <memory> 23#include <testsuite_hooks.h> 24 25struct A 26{ 27}; 28 29std::unique_ptr<A> 30create_unique_ptr() 31{ 32 return std::unique_ptr<A>(new A()); 33} 34 35std::auto_ptr<A> 36create_auto_ptr() 37{ 38 return std::auto_ptr<A>(new A()); 39} 40 41void 42process(std::shared_ptr<A> a) 43{ 44 bool test __attribute__((unused)) = true; 45 46 VERIFY( a.get() != 0 ); 47 VERIFY( a.use_count() == 1 ); 48} 49 50// 20.9.11.2.1 shared_ptr creation [util.smartptr.shared.const] 51 52// Implicit conversion of auto_ptr to shared_ptr is allowed 53 54void 55test01() 56{ 57 process(create_auto_ptr()); 58} 59 60void 61test02() 62{ 63 std::auto_ptr<A> a = create_auto_ptr(); 64 process(std::move(a)); 65} 66 67// Implicit conversion of unique_ptr to shared_ptr is allowed 68 69void 70test03() 71{ 72 process(create_unique_ptr()); 73} 74 75void 76test04() 77{ 78 std::unique_ptr<A> a = create_unique_ptr(); 79 process(std::move(a)); 80} 81 82int 83main() 84{ 85 test01(); 86 test02(); 87 test03(); 88 test04(); 89 return 0; 90} 91