summaryrefslogtreecommitdiff
path: root/libs/python/test/destroy_test.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2013-06-25 22:59:01 +0000
committer <>2013-09-27 11:49:28 +0000
commit8c4528713d907ee2cfd3bfcbbad272c749867f84 (patch)
treec09e2ce80f47b90c85cc720f5139089ad9c8cfff /libs/python/test/destroy_test.cpp
downloadboost-tarball-baserock/morph.tar.gz
Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_54_0.tar.bz2.boost_1_54_0baserock/morph
Diffstat (limited to 'libs/python/test/destroy_test.cpp')
-rw-r--r--libs/python/test/destroy_test.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/libs/python/test/destroy_test.cpp b/libs/python/test/destroy_test.cpp
new file mode 100644
index 000000000..cae95ae91
--- /dev/null
+++ b/libs/python/test/destroy_test.cpp
@@ -0,0 +1,59 @@
+// Copyright David Abrahams 2004. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#include <boost/python/detail/destroy.hpp>
+
+#include <boost/detail/lightweight_test.hpp>
+
+int count;
+int marks[] = {
+ -1
+ , -1, -1
+ , -1, -1, -1, -1
+ , -1
+};
+int* kills = marks;
+
+struct foo
+{
+ foo() : n(count++) {}
+ ~foo()
+ {
+ *kills++ = n;
+ }
+ int n;
+
+ // This used to cause compiler errors with MSVC 9.0.
+ foo& operator~();
+ foo& T();
+};
+
+void assert_destructions(int n)
+{
+ for (int i = 0; i < n; ++i)
+ BOOST_TEST(marks[i] == i);
+ BOOST_TEST(marks[n] == -1);
+}
+
+int main()
+{
+ assert_destructions(0);
+ typedef int a[2];
+
+ foo* f1 = new foo;
+ boost::python::detail::destroy_referent<foo const volatile&>(f1);
+ assert_destructions(1);
+
+ foo* f2 = new foo[2];
+ typedef foo x[2];
+
+ boost::python::detail::destroy_referent<x const&>(f2);
+ assert_destructions(3);
+
+ typedef foo y[2][2];
+ x* f3 = new y;
+ boost::python::detail::destroy_referent<y&>(f3);
+ assert_destructions(7);
+
+ return boost::report_errors();
+}