URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Go to most recent revision |
Only display areas with differences |
Details |
Blame |
View Log
Rev 154 |
Rev 816 |
// { dg-do run }
|
// { dg-do run }
|
//Lifetime of temporaries:
|
//Lifetime of temporaries:
|
//egcs 2.92 performs cleanup for temporaries inside new expressions
|
//egcs 2.92 performs cleanup for temporaries inside new expressions
|
//after the new is complete, not at the end of the full expression.
|
//after the new is complete, not at the end of the full expression.
|
|
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
|
|
bool new_throws;
|
bool new_throws;
|
bool ctor_throws;
|
bool ctor_throws;
|
|
|
int new_done;
|
int new_done;
|
int ctor_done;
|
int ctor_done;
|
int func_done;
|
int func_done;
|
int dtor_done;
|
int dtor_done;
|
int delete_done;
|
int delete_done;
|
|
|
int count;
|
int count;
|
|
|
void init()
|
void init()
|
{
|
{
|
new_throws = ctor_throws = false;
|
new_throws = ctor_throws = false;
|
new_done = ctor_done = func_done = dtor_done = delete_done = count = 0;
|
new_done = ctor_done = func_done = dtor_done = delete_done = count = 0;
|
}
|
}
|
|
|
struct line_error{
|
struct line_error{
|
int line;
|
int line;
|
line_error(int i):line(i){}
|
line_error(int i):line(i){}
|
};
|
};
|
|
|
#define CHECK(cond) if(!(cond))throw line_error(__LINE__);
|
#define CHECK(cond) if(!(cond))throw line_error(__LINE__);
|
|
|
struct A{
|
struct A{
|
A(int){
|
A(int){
|
ctor_done = ++count;
|
ctor_done = ++count;
|
if(ctor_throws)
|
if(ctor_throws)
|
throw 1;
|
throw 1;
|
}
|
}
|
A(const A&){
|
A(const A&){
|
CHECK(false); //no copy constructors in this code
|
CHECK(false); //no copy constructors in this code
|
}
|
}
|
~A(){
|
~A(){
|
dtor_done = ++count;
|
dtor_done = ++count;
|
}
|
}
|
A* addr(){return this;}
|
A* addr(){return this;}
|
};
|
};
|
|
|
struct B{
|
struct B{
|
B(A*){}
|
B(A*){}
|
void* operator new(size_t s){
|
void* operator new(size_t s){
|
new_done = ++count;
|
new_done = ++count;
|
if(new_throws)
|
if(new_throws)
|
throw 1;
|
throw 1;
|
return malloc(s);
|
return malloc(s);
|
}
|
}
|
void operator delete(void *){
|
void operator delete(void *){
|
delete_done = ++count;
|
delete_done = ++count;
|
}
|
}
|
};
|
};
|
|
|
void func(B* )
|
void func(B* )
|
{
|
{
|
func_done = ++count;
|
func_done = ++count;
|
}
|
}
|
|
|
void test1()
|
void test1()
|
{
|
{
|
init();
|
init();
|
try{
|
try{
|
func(new B(A(10).addr()));
|
func(new B(A(10).addr()));
|
}catch(int){
|
}catch(int){
|
}
|
}
|
CHECK(ctor_done==1);
|
CHECK(ctor_done==1);
|
CHECK(new_done==2);
|
CHECK(new_done==2);
|
CHECK(func_done==3);
|
CHECK(func_done==3);
|
CHECK(dtor_done==4);
|
CHECK(dtor_done==4);
|
CHECK(delete_done==0);
|
CHECK(delete_done==0);
|
}
|
}
|
|
|
void test2()
|
void test2()
|
{
|
{
|
init();
|
init();
|
new_throws = true;
|
new_throws = true;
|
try{
|
try{
|
func(new B(A(10).addr()));
|
func(new B(A(10).addr()));
|
}catch(int){
|
}catch(int){
|
}
|
}
|
CHECK(ctor_done==1);
|
CHECK(ctor_done==1);
|
CHECK(new_done==2);
|
CHECK(new_done==2);
|
CHECK(func_done==0);
|
CHECK(func_done==0);
|
CHECK(dtor_done==3);
|
CHECK(dtor_done==3);
|
CHECK(delete_done==0);
|
CHECK(delete_done==0);
|
}
|
}
|
|
|
void test3()
|
void test3()
|
{
|
{
|
init();
|
init();
|
ctor_throws = true;
|
ctor_throws = true;
|
try{
|
try{
|
func(new B(A(10).addr()));
|
func(new B(A(10).addr()));
|
}catch(int){
|
}catch(int){
|
}
|
}
|
CHECK(new_done==0);
|
CHECK(new_done==0);
|
CHECK(ctor_done==1);
|
CHECK(ctor_done==1);
|
CHECK(func_done==0);
|
CHECK(func_done==0);
|
CHECK(dtor_done==0);
|
CHECK(dtor_done==0);
|
CHECK(delete_done==0);
|
CHECK(delete_done==0);
|
}
|
}
|
|
|
int main()
|
int main()
|
{
|
{
|
try{
|
try{
|
test1();
|
test1();
|
test2();
|
test2();
|
test3();
|
test3();
|
}catch(line_error e){
|
}catch(line_error e){
|
printf("Got error in line %d\n",e.line);
|
printf("Got error in line %d\n",e.line);
|
return 1;
|
return 1;
|
}
|
}
|
return 0;
|
return 0;
|
}
|
}
|
|
|
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.