diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/obj-c++.dg/cxx-ivars-2.mm | |
download | cbb-gcc-4.6.4-15d2061ac0796199866debe9ac87130894b0cdd3.tar.bz2 cbb-gcc-4.6.4-15d2061ac0796199866debe9ac87130894b0cdd3.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/obj-c++.dg/cxx-ivars-2.mm')
-rw-r--r-- | gcc/testsuite/obj-c++.dg/cxx-ivars-2.mm | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/gcc/testsuite/obj-c++.dg/cxx-ivars-2.mm b/gcc/testsuite/obj-c++.dg/cxx-ivars-2.mm new file mode 100644 index 000000000..8f836ce90 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/cxx-ivars-2.mm @@ -0,0 +1,79 @@ +// Check if the '- .cxx_construct' and '-.cxx_destruct' methods get called +// and if they perform their desired function. + +// { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } +// { dg-do run { target *-*-darwin* } } +// { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } +// { dg-options "-fobjc-call-cxx-cdtors" } + +#include "../objc-obj-c++-shared/Object1.h" +#include <stdlib.h> +#define CHECK_IF(expr) if(!(expr)) abort() + +static int ctor1_called, ctor2_called, dtor1_called; + +struct bar { + int a, b; + bar(void) { + a = 5; b = 6; + ctor1_called++; + } + ~bar(void) { + a = b = 99; + dtor1_called++; + } +}; + +struct boo: bar { + int c; + boo(int _c = 9): c(_c) { + ctor2_called++; + } +}; + +@interface Baz: Object { +@public + bar aa; +} +@end + +@implementation Baz +@end + +@interface Foo: Baz { +@public + int a; + boo bb; + bar b; + float c; + bar d; +} +@end + +@implementation Foo +@end + +int main (void) +{ + CHECK_IF(!ctor1_called && !ctor2_called && !dtor1_called); /* are we sane? */ + + Baz *baz = [Baz new]; + CHECK_IF(ctor1_called && !ctor2_called && !dtor1_called); + CHECK_IF(baz->aa.a == 5 && baz->aa.b == 6); + ctor1_called = 0; /* reset */ + + [baz free]; + CHECK_IF(!ctor1_called && !ctor2_called && dtor1_called); + dtor1_called = 0; /* reset */ + + Foo *foo = [Foo new]; + CHECK_IF(ctor1_called && ctor2_called && !dtor1_called); + CHECK_IF(foo->bb.a == 5 && foo->bb.b == 6 && foo->bb.c == 9); + CHECK_IF(foo->b.a == 5 && foo->b.b == 6); + CHECK_IF(foo->d.a == 5 && foo->d.b == 6); + ctor1_called = ctor2_called = 0; /* reset */ + + [foo free]; + CHECK_IF(!ctor1_called && !ctor2_called && dtor1_called); +} +#include "../objc-obj-c++-shared/Object1-implementation.h" |