diff options
Diffstat (limited to 'gcc/testsuite/g++.old-deja/g++.brendan/code-gen5.C')
-rwxr-xr-x | gcc/testsuite/g++.old-deja/g++.brendan/code-gen5.C | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/code-gen5.C b/gcc/testsuite/g++.old-deja/g++.brendan/code-gen5.C new file mode 100755 index 0000000..0d59b56 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.brendan/code-gen5.C @@ -0,0 +1,57 @@ +// Special g++ Options: -fthis-is-variable +// GROUPS passed code-generation +// Check that the "this" pointer is zero when a method is +// called for an object pointed to by a null pointer. + +// Normally, the "__builtin_new" operation which actually +// allocates objects in heap space is *not* called at the +// actual point of the "new" keyword. Rather, a check is +// made within each constructor and if the "this" pointer +// value passed in is zero, then the actual allocation of +// memory (via __builtin_new) is done at that point (i.e. +// at the very beginning of the constructor). + +// A special trick allows one to subvert this mechanism. +// Specifically, if a given constructor contains a statement +// like: "this = this", then no attempt will be made to +// implicitly call __builtin_new within that constructor. + +extern "C" void printf (char *, ...); + +struct base { + int member; + + base (); + void member_function (); +}; + +base *base_pointer_1 = 0; +base *base_pointer_2 = 0; + +int errors = 0; + +int main () +{ + //base_pointer_2 = new base(); + base_pointer_1->member_function (); + + if (errors) + printf ("FAIL\n"); + else + printf ("PASS\n"); + + return 0; +} + +base::base () +{ + this = this; + if ((int) this != 0) + errors++; +} + +void base::member_function () +{ + if ((int) this != 0) + errors++; +} |