Commit 7dfded91 by Jonathan Wakely

memory: New file.

	* include/tr1/memory: New file.
	* include/Makefile.am, include/Makefile.in: Add new TR1 header.
	* testsuite/tr1/2_general_utilities/memory/
	enable_shared_from_this/not_shared.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	enable_shared_from_this/not_shared2.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	enable_shared_from_this/not_shared3.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	enable_shared_from_this/shared.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	enable_shared_from_this/still_shared.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/assign/assign.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/assign/auto_ptr.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/assign/auto_ptr_neg.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/assign/auto_ptr_rvalue_neg.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/assign/shared_ptr.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/assign/shared_ptr_neg.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/comparison/cmp.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/cons/auto_ptr.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/cons/auto_ptr_neg.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/cons/copy.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/cons/default.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/cons/pointer.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/cons/weak_ptr.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/cons/weak_ptr_expired.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/dest/dest.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/misc/io.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/misc/swap.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/modifiers/reset.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/modifiers/reset_neg.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/modifiers/swap.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/modifiers/swap_neg.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/observers/bool_conv.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/observers/get.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/observers/unique.cc: New test.
	* testsuite/tr1/2_general_utilities/memory/
	shared_ptr/observers/use_count.cc: New test.

From-SVN: r95361
parent 11996a3c
2005-02-21 Jonathan Wakely <redi@gcc.gnu.org>
* include/tr1/memory: New file.
* include/Makefile.am, include/Makefile.in: Add new TR1 header.
* testsuite/tr1/2_general_utilities/memory/
enable_shared_from_this/not_shared.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
enable_shared_from_this/not_shared2.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
enable_shared_from_this/not_shared3.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
enable_shared_from_this/shared.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
enable_shared_from_this/still_shared.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/assign/assign.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/assign/auto_ptr.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/assign/auto_ptr_neg.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/assign/auto_ptr_rvalue_neg.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/assign/shared_ptr.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/assign/shared_ptr_neg.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/comparison/cmp.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/cons/auto_ptr.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/cons/auto_ptr_neg.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/cons/copy.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/cons/default.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/cons/pointer.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/cons/weak_ptr.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/cons/weak_ptr_expired.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/dest/dest.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/misc/io.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/misc/swap.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/modifiers/reset.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/modifiers/reset_neg.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/modifiers/swap.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/modifiers/swap_neg.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/observers/bool_conv.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/observers/get.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/observers/unique.cc: New test.
* testsuite/tr1/2_general_utilities/memory/
shared_ptr/observers/use_count.cc: New test.
2005-02-21 Paolo Carlini <pcarlini@suse.de>
* include/tr1/type_traits (is_member_function_pointer):
......
......@@ -229,6 +229,7 @@ tr1_builddir = ./tr1
tr1_headers = \
${tr1_srcdir}/array \
${tr1_srcdir}/functional \
${tr1_srcdir}/memory \
${tr1_srcdir}/tuple \
${tr1_srcdir}/utility \
${tr1_srcdir}/type_traits \
......@@ -569,7 +570,7 @@ ${host_builddir}/gthr-default.h: ${toplevel_srcdir}/gcc/${glibcxx_thread_h} \
# Build a precompiled C++ include, stdc++.h.gch.
${pch_input}: ${allstamped} ${host_builddir}/c++config.h ${pch_source}
touch ${pch_input}; \
cp ${pch_source} ${pch_input}; \
if [ ! -d "${pch_output_builddir}" ]; then \
mkdir -p ${pch_output_builddir}; \
fi; \
......
......@@ -445,6 +445,7 @@ tr1_builddir = ./tr1
tr1_headers = \
${tr1_srcdir}/array \
${tr1_srcdir}/functional \
${tr1_srcdir}/memory \
${tr1_srcdir}/tuple \
${tr1_srcdir}/utility \
${tr1_srcdir}/type_traits \
......@@ -944,7 +945,7 @@ ${host_builddir}/gthr-default.h: ${toplevel_srcdir}/gcc/${glibcxx_thread_h} \
# Build a precompiled C++ include, stdc++.h.gch.
${pch_input}: ${allstamped} ${host_builddir}/c++config.h ${pch_source}
touch ${pch_input}; \
cp ${pch_source} ${pch_input}; \
if [ ! -d "${pch_output_builddir}" ]; then \
mkdir -p ${pch_output_builddir}; \
fi; \
......
// { dg-do run { xfail *-*-* } }
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 2.2.5 Template class enable_shared_from_this [tr.util.smartptr.enab]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct X : public std::tr1::enable_shared_from_this<X>
{
};
int
test01()
{
bool test __attribute__((unused)) = true;
X x;
try
{
std::tr1::shared_ptr<X> p = x.shared_from_this();
}
catch (const std::tr1::bad_weak_ptr&)
{
__throw_exception_again;
}
catch (...)
{
}
return 0;
}
int
main()
{
test01();
return 0;
}
// { dg-do run { xfail *-*-* } }
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 2.2.5 Template class enable_shared_from_this [tr.util.smartptr.enab]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct X : public std::tr1::enable_shared_from_this<X>
{
};
int
test01()
{
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<X> p(new X);
X x(*p); // copy of shared object should not be shared
try
{
std::tr1::shared_ptr<X> p = x.shared_from_this();
}
catch (const std::tr1::bad_weak_ptr&)
{
__throw_exception_again;
}
return 0;
}
int
main()
{
test01();
return 0;
}
// { dg-do run { xfail *-*-* } }
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 2.2.5 Template class enable_shared_from_this [tr.util.smartptr.enab]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct X : public std::tr1::enable_shared_from_this<X>
{
};
int
test01()
{
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<X> p(new X);
X x;
x = *p; // copy of shared object should not be shared
try
{
std::tr1::shared_ptr<X> p = x.shared_from_this();
}
catch (const std::tr1::bad_weak_ptr&)
{
__throw_exception_again;
}
return 0;
}
int
main()
{
test01();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 2.2.5 Template class enable_shared_from_this [tr.util.smartptr.enab]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct X : public std::tr1::enable_shared_from_this<X>
{
};
int
test01()
{
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<X> p(new X);
std::tr1::shared_ptr<X> q = p->shared_from_this();
VERIFY( p == q );
VERIFY( !(p < q) && !(q < p) ); // p and q share ownership
return 0;
}
int
main()
{
test01();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 2.2.5 Template class enable_shared_from_this [tr.util.smartptr.enab]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct X : public std::tr1::enable_shared_from_this<X>
{
};
int
test01()
{
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<X> p(new X);
*p = X(); // assigning to shared object doesn't stop it being shared
try
{
std::tr1::shared_ptr<X> p2 = p->shared_from_this();
}
catch (const std::tr1::bad_weak_ptr&)
{
test = false;
}
VERIFY( test );
return 0;
}
int
main()
{
test01();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A
{
A() { ++ctor_count; }
virtual ~A() { ++dtor_count; }
static long ctor_count;
static long dtor_count;
};
long A::ctor_count = 0;
long A::dtor_count = 0;
struct reset_count_struct
{
~reset_count_struct()
{
A::ctor_count = 0;
A::dtor_count = 0;
}
};
// 2.2.3.3 shared_ptr assignment [tr.util.smartptr.shared.assign]
// Assignment from shared_ptr<Y>
int
test01()
{
reset_count_struct __attribute__((unused)) reset;
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<A> a;
a = std::tr1::shared_ptr<A>(new A);
VERIFY( a.get() != 0 );
VERIFY( A::ctor_count == 1 );
VERIFY( A::dtor_count == 0 );
a = std::tr1::shared_ptr<A>();
VERIFY( a.get() == 0 );
VERIFY( A::ctor_count == 1 );
VERIFY( A::dtor_count == 1 );
}
int
main()
{
test01();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A
{
A() { ++ctor_count; }
virtual ~A() { ++dtor_count; }
static long ctor_count;
static long dtor_count;
};
long A::ctor_count = 0;
long A::dtor_count = 0;
struct B : A
{
B() { ++ctor_count; }
virtual ~B() { ++dtor_count; }
static long ctor_count;
static long dtor_count;
};
long B::ctor_count = 0;
long B::dtor_count = 0;
struct reset_count_struct
{
~reset_count_struct()
{
A::ctor_count = 0;
A::dtor_count = 0;
B::ctor_count = 0;
B::dtor_count = 0;
}
};
// 2.2.3.3 shared_ptr assignment [tr.util.smartptr.shared.assign]
// Assignment from auto_ptr<Y>
int
test01()
{
reset_count_struct __attribute__((unused)) reset;
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<A> a(new A);
std::auto_ptr<B> b(new B);
a = b;
VERIFY( a.get() != 0 );
VERIFY( b.get() == 0 );
VERIFY( A::ctor_count == 2 );
VERIFY( A::dtor_count == 1 );
VERIFY( B::ctor_count == 1 );
VERIFY( B::dtor_count == 0 );
return 0;
}
int
main()
{
test01();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A { };
struct B { };
// 2.2.3.3 shared_ptr assignment [tr.util.smartptr.shared.assign]
// Assignment from incompatible auto_ptr<Y>
int
test01()
{
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<A> a;
std::auto_ptr<B> b;
a = b; // { dg-error "here" }
return 0;
}
int
main()
{
test01();
return 0;
}
// { dg-error "In constructor" "" { target *-*-* } 0 }
// { dg-error "cannot convert" "" { target *-*-* } 0 }
// { dg-error "instantiated from" "" { target *-*-* } 0 }
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A { };
std::auto_ptr<A> source() { return std::auto_ptr<A>(); }
// 2.2.3.3 shared_ptr assignment [tr.util.smartptr.shared.assign]
// Assignment from rvalue auto_ptr
int
test01()
{
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<A> a;
a = source(); // { dg-error "no match" }
return 0;
}
int
main()
{
test01();
return 0;
}
// { dg-error "auto_ptr" "" { target *-*-* } 0 }
// { dg-error "shared_ptr" "" { target *-*-* } 0 }
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A
{
A() { ++ctor_count; }
virtual ~A() { ++dtor_count; }
static long ctor_count;
static long dtor_count;
};
long A::ctor_count = 0;
long A::dtor_count = 0;
struct B : A
{
B() { ++ctor_count; }
virtual ~B() { ++dtor_count; }
static long ctor_count;
static long dtor_count;
};
long B::ctor_count = 0;
long B::dtor_count = 0;
struct reset_count_struct
{
~reset_count_struct()
{
A::ctor_count = 0;
A::dtor_count = 0;
B::ctor_count = 0;
B::dtor_count = 0;
}
};
// 2.2.3.3 shared_ptr assignment [tr.util.smartptr.shared.assign]
// Assignment from shared_ptr<Y>
int
test01()
{
reset_count_struct __attribute__((unused)) reset;
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<A> a;
a = std::tr1::shared_ptr<A>();
VERIFY( a.get() == 0 );
VERIFY( A::ctor_count == 0 );
VERIFY( A::dtor_count == 0 );
VERIFY( B::ctor_count == 0 );
VERIFY( B::dtor_count == 0 );
a = std::tr1::shared_ptr<A>(new A);
VERIFY( a.get() != 0 );
VERIFY( A::ctor_count == 1 );
VERIFY( A::dtor_count == 0 );
VERIFY( B::ctor_count == 0 );
VERIFY( B::dtor_count == 0 );
a = std::tr1::shared_ptr<B>(new B);
VERIFY( a.get() != 0 );
VERIFY( A::ctor_count == 2 );
VERIFY( A::dtor_count == 1 );
VERIFY( B::ctor_count == 1 );
VERIFY( B::dtor_count == 0 );
}
int
main()
{
test01();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A { };
struct B { };
// 2.2.3.3 shared_ptr assignment [tr.util.smartptr.shared.assign]
// Assignment from incompatible shared_ptr<Y>
int
test01()
{
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<A> a;
std::tr1::shared_ptr<B> b;
a = b; // { dg-error "here" }
return 0;
}
int
main()
{
test01();
return 0;
}
// { dg-error "In member function" "" { target *-*-* } 0 }
// { dg-error "cannot convert" "" { target *-*-* } 0 }
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A
{
virtual ~A() { }
};
struct B : A
{
};
// 2.2.3.6 shared_ptr comparison [tr.util.smartptr.shared.cmp]
int
test01()
{
// test empty shared_ptrs compare equivalent
std::tr1::shared_ptr<A> p1;
std::tr1::shared_ptr<B> p2;
VERIFY( p1 == p2 );
VERIFY( !(p1 != p2) );
VERIFY( !(p1 < p2) && !(p2 < p1) );
return 0;
}
// Construction from pointer
int
test02()
{
std::tr1::shared_ptr<A> A_default;
std::tr1::shared_ptr<A> A_from_A(new A);
VERIFY( A_default != A_from_A );
VERIFY( !(A_default == A_from_A) );
VERIFY( (A_default < A_from_A) || (A_from_A < A_default) );
std::tr1::shared_ptr<B> B_from_B(new B);
VERIFY( B_from_B != A_from_A );
VERIFY( !(B_from_B == A_from_A) );
VERIFY( (B_from_B < A_from_A) || (A_from_A < B_from_B) );
A_from_A.reset();
VERIFY( A_default == A_from_A );
VERIFY( !(A_default != A_from_A) );
VERIFY( !(A_default < A_from_A) && !(A_from_A < A_default) );
B_from_B.reset();
VERIFY( B_from_B == A_from_A );
VERIFY( !(B_from_B != A_from_A) );
VERIFY( !(B_from_B < A_from_A) && !(A_from_A < B_from_B) );
return 0;
}
int
main()
{
test01();
test02();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A { };
// 2.2.3.1 shared_ptr constructors [tr.util.smartptr.shared.const]
// Construction from auto_ptr
int
test01()
{
bool test __attribute__((unused)) = true;
std::auto_ptr<A> a(new A);
std::tr1::shared_ptr<A> a2(a);
VERIFY( a.get() == 0 );
VERIFY( a2.get() != 0 );
VERIFY( a2.use_count() == 1 );
return 0;
}
int
main()
{
test01();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A { };
// 2.2.3.3 shared_ptr assignment [tr.util.smartptr.shared.const]
// Construction from const auto_ptr
int
test01()
{
bool test __attribute__((unused)) = true;
const std::auto_ptr<A> a;
std::tr1::shared_ptr<A> p(a); // { dg-error "no match" }
return 0;
}
int
main()
{
test01();
return 0;
}
// { dg-error "shared_ptr" "candidates are" { target *-*-* } 499 }
// { dg-error "shared_ptr" "" { target *-*-* } 489 }
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A
{
A() { ++ctor_count; }
virtual ~A() { ++dtor_count; }
static long ctor_count;
static long dtor_count;
};
long A::ctor_count = 0;
long A::dtor_count = 0;
struct B : A
{
B() { ++ctor_count; }
virtual ~B() { ++dtor_count; }
static long ctor_count;
static long dtor_count;
};
long B::ctor_count = 0;
long B::dtor_count = 0;
void deleter(A* p) { delete p; }
struct reset_count_struct
{
~reset_count_struct()
{
A::ctor_count = 0;
A::dtor_count = 0;
B::ctor_count = 0;
B::dtor_count = 0;
}
};
// 2.2.3.1 shared_ptr constructors [tr.util.smartptr.shared.const]
// Copy construction
int test01()
{
reset_count_struct __attribute__((unused)) reset;
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<A> a1;
std::tr1::shared_ptr<A> a2(a1);
VERIFY( a2.use_count() == 0 );
VERIFY( A::ctor_count == 0 );
VERIFY( A::dtor_count == 0 );
VERIFY( B::ctor_count == 0 );
VERIFY( B::dtor_count == 0 );
return 0;
}
int
test02()
{
reset_count_struct __attribute__((unused)) reset;
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<A> a1(new A);
std::tr1::shared_ptr<A> a2(a1);
VERIFY( a2.use_count() == 2 );
VERIFY( A::ctor_count == 1 );
VERIFY( A::dtor_count == 0 );
VERIFY( B::ctor_count == 0 );
VERIFY( B::dtor_count == 0 );
return 0;
}
int
test03()
{
reset_count_struct __attribute__((unused)) reset;
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<B> b(new B);
std::tr1::shared_ptr<A> a(b);
VERIFY( a.use_count() == 2 );
VERIFY( A::ctor_count == 1 );
VERIFY( A::dtor_count == 0 );
VERIFY( B::ctor_count == 1 );
VERIFY( B::dtor_count == 0 );
return 0;
}
int
test04()
{
reset_count_struct __attribute__((unused)) reset;
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<B> b(new B, &deleter);
std::tr1::shared_ptr<A> a(b);
VERIFY( a.use_count() == 2 );
VERIFY( A::ctor_count == 1 );
VERIFY( A::dtor_count == 0 );
VERIFY( B::ctor_count == 1 );
VERIFY( B::dtor_count == 0 );
return 0;
}
int
main()
{
test01();
test02();
test03();
test04();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A { };
// 2.2.3.1 shared_ptr constructors [tr.util.smartptr.shared.const]
// Default construction
int
test01()
{
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<A> a;
VERIFY( a.get() == 0 );
return 0;
}
int
main()
{
test01();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A { };
struct B : A { };
// 2.2.3.1 shared_ptr constructors [tr.util.smartptr.shared.const]
// Construction from pointer
int
test01()
{
bool test __attribute__((unused)) = true;
A * const a = 0;
std::tr1::shared_ptr<A> p(a);
VERIFY( p.get() == 0 );
VERIFY( p.use_count() == 1 );
return 0;
}
int
test02()
{
bool test __attribute__((unused)) = true;
A * const a = new A;
std::tr1::shared_ptr<A> p(a);
VERIFY( p.get() == a );
VERIFY( p.use_count() == 1 );
return 0;
}
int
test03()
{
bool test __attribute__((unused)) = true;
B * const b = new B;
std::tr1::shared_ptr<A> p(b);
VERIFY( p.get() == b );
VERIFY( p.use_count() == 1 );
return 0;
}
int
main()
{
test01();
test02();
test02();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A { };
// 2.2.3.1 shared_ptr constructors [tr.util.smartptr.shared.const]
// Construction from weak_ptr
int
test01()
{
bool test __attribute__((unused)) = true;
A * const a = new A;
std::tr1::shared_ptr<A> a1(a);
std::tr1::weak_ptr<A> wa(a1);
std::tr1::shared_ptr<A> a2(wa);
VERIFY( a2.get() == a );
VERIFY( a2.use_count() == wa.use_count() );
return 0;
}
int
main()
{
test01();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A { };
// 2.2.3.1 shared_ptr constructors [tr.util.smartptr.shared.const]
// Construction from expired weak_ptr
int
test01()
{
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<A> a1(new A);
std::tr1::weak_ptr<A> wa(a1);
a1.reset();
try
{
std::tr1::shared_ptr<A> a2(wa);
}
catch (const std::tr1::bad_weak_ptr&)
{
// Expected.
}
catch (...)
{
// Failed.
__throw_exception_again;
}
VERIFY( wa.expired() );
return 0;
}
int
main()
{
test01();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A
{
A() { ++ctor_count; }
~A() { ++dtor_count; }
static long ctor_count;
static long dtor_count;
};
long A::ctor_count = 0;
long A::dtor_count = 0;
struct B : A
{
B() { ++ctor_count; }
~B() { ++dtor_count; }
static long ctor_count;
static long dtor_count;
};
long B::ctor_count = 0;
long B::dtor_count = 0;
struct D
{
void operator()(const B* p) { delete p; ++delete_count; }
static long delete_count;
};
long D::delete_count = 0;
struct reset_count_struct
{
~reset_count_struct()
{
A::ctor_count = 0;
A::dtor_count = 0;
B::ctor_count = 0;
B::dtor_count = 0;
D::delete_count = 0;
}
};
// 2.2.3.2 shared_ptr destructor [tr.util.smartptr.shared.dest]
// empty shared_ptr
int
test01()
{
reset_count_struct __attribute__((unused)) reset;
bool test __attribute__((unused)) = true;
{
std::tr1::shared_ptr<A> a;
}
VERIFY( A::ctor_count == 0 );
VERIFY( A::dtor_count == 0 );
VERIFY( B::ctor_count == 0 );
VERIFY( B::dtor_count == 0 );
VERIFY( D::delete_count == 0 );
return 0;
}
// shared ownership
int
test02()
{
reset_count_struct __attribute__((unused)) reset;
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<A> a;
{
a = std::tr1::shared_ptr<A>(new B, D());
}
VERIFY( A::ctor_count == 1 );
VERIFY( A::dtor_count == 0 );
VERIFY( B::ctor_count == 1 );
VERIFY( B::dtor_count == 0 );
VERIFY( D::delete_count == 0 );
return 0;
}
// exclusive ownership
int
test03()
{
reset_count_struct __attribute__((unused)) reset;
bool test __attribute__((unused)) = true;
{
std::tr1::shared_ptr<A> a1(new B);
std::tr1::shared_ptr<A> a2(new B, D());
}
VERIFY( A::ctor_count == 2 );
VERIFY( A::dtor_count == 2 );
VERIFY( B::ctor_count == 2 );
VERIFY( B::dtor_count == 2 );
VERIFY( D::delete_count == 1 );
return 0;
}
int
main()
{
test01();
test02();
test03();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <sstream>
#include <testsuite_hooks.h>
struct A { };
// 2.2.3.7 shared_ptr I/O [tr.util.smartptr.shared.io]
// operator<<
int
test01()
{
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<A> p(new A);
std::ostringstream buf;
buf << p;
const std::string s = buf.str();
buf.str("");
buf << p.get();
VERIFY( s == buf.str() );
return 0;
}
int
main()
{
test01();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A { };
// 2.2.3.8 shared_ptr specialized algorithms [tr.util.smartptr.shared.spec]
// std::swap
int
test01()
{
bool test __attribute__((unused)) = true;
A * const a1 = new A;
A * const a2 = new A;
std::tr1::shared_ptr<A> p1(a1);
std::tr1::shared_ptr<A> p2(a2);
std::swap(p1, p2);
VERIFY( p1.get() == a2 );
VERIFY( p2.get() == a1 );
return 0;
}
int
main()
{
test01();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A { };
struct B : A { };
struct D
{
void operator()(B* p) { delete p; ++delete_count; }
static long delete_count;
};
long D::delete_count = 0;
// 2.2.3.4 shared_ptr modifiers [tr.util.smartptr.shared.mod]
// reset
int
test01()
{
bool test __attribute__((unused)) = true;
A * const a = new A;
std::tr1::shared_ptr<A> p1(a);
std::tr1::shared_ptr<A> p2(p1);
p1.reset();
VERIFY( p1.get() == 0 );
VERIFY( p2.get() == a );
return 0;
}
int
test02()
{
bool test __attribute__((unused)) = true;
A * const a = new A;
B * const b = new B;
std::tr1::shared_ptr<A> p1(a);
std::tr1::shared_ptr<A> p2(p1);
p1.reset(b);
VERIFY( p1.get() == b );
VERIFY( p2.get() == a );
return 0;
}
int
test03()
{
bool test __attribute__((unused)) = true;
{
std::tr1::shared_ptr<A> p1;
p1.reset(new B, D());
}
VERIFY( D::delete_count == 1 );
return 0;
}
int
main()
{
test01();
test02();
test03();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A { };
// 2.2.3.4 shared_ptr modifiers [tr.util.smartptr.shared.mod]
// reset
int
test01()
{
bool test __attribute__((unused)) = true;
const std::tr1::shared_ptr<A> p1(new A);
p1.reset(); // { dg-error "discards qualifiers" }
return 0;
}
int
main()
{
test01();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A { };
// 2.2.3.4 shared_ptr modifiers [tr.util.smartptr.shared.mod]
// swap
int
test01()
{
bool test __attribute__((unused)) = true;
A * const a1 = new A;
A * const a2 = new A;
std::tr1::shared_ptr<A> p1(a1);
std::tr1::shared_ptr<A> p2(a2);
p1.swap(p2);
VERIFY( p1.get() == a2 );
VERIFY( p2.get() == a1 );
return 0;
}
int
main()
{
test01();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A { };
// 2.2.3.4 shared_ptr modifiers [tr.util.smartptr.shared.mod]
// swap
int
test01()
{
bool test __attribute__((unused)) = true;
const std::tr1::shared_ptr<A> p1(new A);
std::tr1::shared_ptr<A> p2(new A);
p1.swap(p2); // { dg-error "discards qualifiers" }
return 0;
}
int
main()
{
test01();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A { };
// 2.2.3.5 shared_ptr observers [tr.util.smartptr.shared.obs]
// conversion to bool
int
test01()
{
bool test __attribute__((unused)) = true;
const std::tr1::shared_ptr<A> p1;
VERIFY( p1 == false );
const std::tr1::shared_ptr<A> p2(p1);
VERIFY( p2 == false );
return 0;
}
int
test02()
{
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<A> p1(new A);
VERIFY( p1 );
std::tr1::shared_ptr<A> p2(p1);
VERIFY( p2 );
p1.reset();
VERIFY( !p1 );
VERIFY( p2 );
return 0;
}
int
test03()
{
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<A> p1(new A);
std::tr1::shared_ptr<A> p2(p1);
p2.reset(new A);
VERIFY( p1 );
VERIFY( p2 );
return 0;
}
int
main()
{
test01();
test02();
test03();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A
{
A() : i() {}
int i;
};
// 2.2.3.5 shared_ptr observers [tr.util.smartptr.shared.obs]
// get
int
test01()
{
bool test __attribute__((unused)) = true;
A * const a = new A;
const std::tr1::shared_ptr<A> p(a);
VERIFY( p.get() == a );
return 0;
}
// operator*
int
test02()
{
bool test __attribute__((unused)) = true;
A * const a = new A;
const std::tr1::shared_ptr<A> p(a);
VERIFY( &*p == a );
return 0;
}
// operator->
int
test03()
{
bool test __attribute__((unused)) = true;
A * const a = new A;
const std::tr1::shared_ptr<A> p(a);
VERIFY( &p->i == &a->i );
return 0;
}
int
main()
{
test01();
test02();
test03();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A { };
// 2.2.3.5 shared_ptr observers [tr.util.smartptr.shared.obs]
// unique
int
test01()
{
bool test __attribute__((unused)) = true;
const std::tr1::shared_ptr<A> p1;
VERIFY( !p1.unique() );
const std::tr1::shared_ptr<A> p2(p1);
VERIFY( !p1.unique() );
return 0;
}
int
test02()
{
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<A> p1(new A);
VERIFY( p1.unique() );
std::tr1::shared_ptr<A> p2(p1);
VERIFY( !p1.unique() );
p1.reset();
VERIFY( !p1.unique() );
VERIFY( p2.unique() );
return 0;
}
int
test03()
{
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<A> p1(new A);
std::tr1::shared_ptr<A> p2(p1);
p2.reset(new A);
VERIFY( p1.unique() );
VERIFY( p2.unique() );
return 0;
}
int
main()
{
test01();
test02();
test03();
return 0;
}
// Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
#include <tr1/memory>
#include <testsuite_hooks.h>
struct A { };
struct B : A { };
// 2.2.3.5 shared_ptr observers [tr.util.smartptr.shared.obs]
// use_count
int
test01()
{
bool test __attribute__((unused)) = true;
const std::tr1::shared_ptr<A> p1;
VERIFY( p1.use_count() == 0 );
const std::tr1::shared_ptr<A> p2(p1);
VERIFY( p1.use_count() == 0 );
return 0;
}
int
test02()
{
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<A> p1(new A);
std::tr1::shared_ptr<A> p2(p1);
p1.reset();
VERIFY( p1.use_count() == 0 );
VERIFY( p2.use_count() == 1 );
return 0;
}
int
test03()
{
bool test __attribute__((unused)) = true;
std::tr1::shared_ptr<A> p1(new A);
std::tr1::shared_ptr<A> p2(p1);
p2.reset(new B);
VERIFY( p1.use_count() == 1 );
VERIFY( p2.use_count() == 1 );
return 0;
}
int
main()
{
test01();
test02();
test03();
return 0;
}
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