Commit ca6d8cae by Jason Merrill

new

From-SVN: r16930
parent 9762d48d
// Bug: obj gets destroyed twice because the fixups for the return are
// inside its cleanup region.
extern "C" int printf (const char *, ...);
int d;
struct myExc { };
struct myExcRaiser {
~myExcRaiser() { throw myExc(); }
};
struct stackObj {
~stackObj() { ++d; printf ("stackObj::~stackObj()\n"); };
};
int test()
{
myExcRaiser rais;
stackObj obj;
return 0;
}
int main()
{
try {
test();
}
catch (myExc &) {
return d != 1;
}
return 1;
}
// Test that a throw in foo destroys the A, but does not free the memory.
#include <stddef.h>
#include <stdlib.h>
#include <new.h>
struct A {
A();
~A();
};
struct B {
B (A);
};
void foo (B*);
int newed, created;
main ()
{
try {
foo (new B (A ()));
} catch (...) { }
return !(newed && !created);
}
A::A() { created = 1; }
A::~A() { created = 0; }
B::B(A) { }
void foo (B*) { throw 1; }
void* operator new (size_t size) throw (std::bad_alloc)
{
++newed;
return (void *) malloc (size);
}
void operator delete (void *p) throw ()
{
--newed;
free (p);
}
// Test that a throw in B's constructor destroys the A and frees the memory.
#include <stddef.h>
#include <stdlib.h>
#include <new.h>
struct A {
A();
~A();
};
struct B {
B (A);
};
void foo (B*);
int newed, created;
main ()
{
try {
foo (new B (A ()));
} catch (...) { }
return !(!newed && !created);
}
A::A() { created = 1; }
A::~A() { created = 0; }
B::B(A) { throw 1; }
void foo (B*) { }
void* operator new (size_t size) throw (std::bad_alloc)
{
++newed;
return (void *) malloc (size);
}
void operator delete (void *p) throw ()
{
--newed;
free (p);
}
// Bug: catching pointers by reference doesn't work right.
extern "C" int printf (const char *, ...);
struct E {
int x;
E(int i) { x = i; };
};
int main()
{
try {
E *p = new E(5);
throw p;
}
catch (E *&e) {
printf ("address of e is 0x%x\n", (long)e);
return !(long(e) != 5 && e->x == 5);
}
return 2;
}
// Testcase for proper handling of rethrow.
#include <stdio.h>
int c, d;
struct A
{
int i;
A () { i = ++c; printf ("A() %d\n", i); }
A (const A&) { i = ++c; printf ("A(const A&) %d\n", i); }
~A() { printf ("~A() %d\n", i); ++d; }
};
int
main ()
{
try
{
try
{
printf ("Throwing 1...\n");
throw A();
}
catch (A)
{
try
{
printf ("Throwing 2...\n");
throw;
}
catch (A)
{
printf ("Throwing 3...\n");
throw A();
}
}
}
catch (A)
{
printf ("Caught.\n");
}
printf ("c == %d, d == %d\n", c, d);
return c != d;
}
// Testcase for proper handling of rethrow.
#include <stdio.h>
int c, d;
struct A
{
int i;
A () { i = ++c; printf ("A() %d\n", i); }
A (const A&) { i = ++c; printf ("A(const A&) %d\n", i); }
~A() { printf ("~A() %d\n", i); ++d; }
};
int
main ()
{
try
{
try
{
printf ("Throwing 1...\n");
throw A();
}
catch (A)
{
try
{
printf ("Throwing 2...\n");
throw;
}
catch (A)
{
printf ("Falling out...\n");
}
}
}
catch (A)
{
printf ("Caught.\n");
}
printf ("c == %d, d == %d\n", c, d);
return c != d;
}
// Special g++ Options: -w
// PRMS Id: 4342 (second testcase) // PRMS Id: 4342 (second testcase)
// Bug: g++ still can't deal with ambiguous inheritance in destructor calls. // Bug: g++ still can't deal with ambiguous inheritance in destructor calls.
// Build don't link: // Build don't link:
...@@ -32,10 +33,10 @@ struct ccScreenObj : public ccScreenObjRep ...@@ -32,10 +33,10 @@ struct ccScreenObj : public ccScreenObjRep
{}; {};
struct ccVSTool : public ccImpExp, public ccUnwind struct ccVSTool : public ccImpExp, public ccUnwind
{}; // gets bogus error - XFAIL *-*-* {};
struct ccSCCP : public ccVSTool struct ccSCCP : public ccVSTool
{}; // gets bogus error - XFAIL *-*-* {};
void foo () void foo ()
{ {
......
// Build don't link:
struct U {
static int STATIC;
};
template <int* x> class FOO {
public:
enum { n = 0 };
};
template <class A> class BAR {
public:
enum { n = FOO<&A::STATIC>::n };
};
int n = BAR<U>::n;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment