1 // Copyright David Abrahams 2004. Distributed under the Boost 2 // Software License, Version 1.0. (See accompanying 3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 #include <boost/python/detail/destroy.hpp> 5 6 #include <boost/detail/lightweight_test.hpp> 7 8 int count; 9 int marks[] = { 10 -1 11 , -1, -1 12 , -1, -1, -1, -1 13 , -1 14 }; 15 int* kills = marks; 16 17 struct foo 18 { foofoo19 foo() : n(count++) {} ~foofoo20 ~foo() 21 { 22 *kills++ = n; 23 } 24 int n; 25 26 // This used to cause compiler errors with MSVC 9.0. 27 foo& operator~(); 28 foo& T(); 29 }; 30 assert_destructions(int n)31 void assert_destructions(int n) 32 { 33 for (int i = 0; i < n; ++i) 34 BOOST_TEST(marks[i] == i); 35 BOOST_TEST(marks[n] == -1); 36 } 37 main()38 int main() 39 { 40 assert_destructions(0); 41 42 foo* f1 = new foo; 43 boost::python::detail::destroy_referent<foo const volatile&>(f1); 44 assert_destructions(1); 45 46 foo* f2 = new foo[2]; 47 typedef foo x[2]; 48 49 boost::python::detail::destroy_referent<x const&>(f2); 50 assert_destructions(3); 51 52 typedef foo y[2][2]; 53 x* f3 = new y; 54 boost::python::detail::destroy_referent<y&>(f3); 55 assert_destructions(7); 56 57 return boost::report_errors(); 58 } 59