diff --git a/regress/usr.bin/Makefile b/regress/usr.bin/Makefile index 6d005ea8952c..36a943b967f5 100644 --- a/regress/usr.bin/Makefile +++ b/regress/usr.bin/Makefile @@ -1,5 +1,6 @@ -# $NetBSD: Makefile,v 1.14 2007/02/19 19:42:50 rmind Exp $ +# $NetBSD: Makefile,v 1.15 2007/09/17 17:37:48 drochner Exp $ -SUBDIR+= basename bzip2 config cut dirname grep gzip m4 make rtld sdiff sort xlint +SUBDIR+= basename bzip2 c++ config cut dirname grep gzip m4 make rtld +SUBDIR+= sdiff sort xlint .include diff --git a/regress/usr.bin/c++/Makefile b/regress/usr.bin/c++/Makefile new file mode 100644 index 000000000000..4d173c9b4761 --- /dev/null +++ b/regress/usr.bin/c++/Makefile @@ -0,0 +1,5 @@ +# $NetBSD: Makefile,v 1.1 2007/09/17 17:37:48 drochner Exp $ + +SUBDIR= static_destructor + +.include diff --git a/regress/usr.bin/c++/static_destructor/Makefile b/regress/usr.bin/c++/static_destructor/Makefile new file mode 100644 index 000000000000..340c1c17385a --- /dev/null +++ b/regress/usr.bin/c++/static_destructor/Makefile @@ -0,0 +1,11 @@ +# $NetBSD: Makefile,v 1.1 2007/09/17 17:37:48 drochner Exp $ + +PROG_CXX= static_destructor +NOMAN= # defined + +regress: + ./${PROG} > out && diff out ${.CURDIR}/expected + +CLEANFILES+= out + +.include diff --git a/regress/usr.bin/c++/static_destructor/expected b/regress/usr.bin/c++/static_destructor/expected new file mode 100644 index 000000000000..5590d0496c3b --- /dev/null +++ b/regress/usr.bin/c++/static_destructor/expected @@ -0,0 +1,4 @@ +constructor A +constructor B +destructor B : i = 1 +destructor A : i = 10 diff --git a/regress/usr.bin/c++/static_destructor/static_destructor.cc b/regress/usr.bin/c++/static_destructor/static_destructor.cc new file mode 100644 index 000000000000..b0bcc7f4494a --- /dev/null +++ b/regress/usr.bin/c++/static_destructor/static_destructor.cc @@ -0,0 +1,37 @@ +/* $NetBSD: static_destructor.cc,v 1.1 2007/09/17 17:37:49 drochner Exp $ */ + +/* + * Tests proper order of destructor calls + * (must be in reverse order of constructor completion). + * from the gcc mailing list + */ + +#include +using namespace std; + +class A +{ +public: + int i; + A(int j) : i(j) { cout << "constructor A" << endl; } + ~A() { cout << "destructor A : i = " << i << endl; } +}; + +class B +{ +public: + A *n; + B() { + static A p(1); + n = &p; + cout << "constructor B" << endl; + } + ~B() { + cout << "destructor B : i = " << n->i << endl; + n->i = 10; + } +}; + +class B x1; + +int main (void) { return 0; }