OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc1/] [gcc/] [testsuite/] [g++.old-deja/] [g++.other/] [singleton.C] - Diff between revs 305 and 338

Only display areas with differences | Details | Blame | View Log

Rev 305 Rev 338
// { dg-do run  }
// { dg-do run  }
// This tests two things:
// This tests two things:
// 1. there is an annoying warning.
// 1. there is an annoying warning.
// singleton.C:26: warning: `class singleton' only defines private constructors and has no friends
// singleton.C:26: warning: `class singleton' only defines private constructors and has no friends
// egcs fails to see that there is a public static accessor function.
// egcs fails to see that there is a public static accessor function.
// 2. the program crashes, because apparently the static variable s in
// 2. the program crashes, because apparently the static variable s in
// singleton::instance() is considered constructed although the ctor
// singleton::instance() is considered constructed although the ctor
// exited via an exception. (crash changed to nonzero return here)
// exited via an exception. (crash changed to nonzero return here)
class singleton {
class singleton {
public:
public:
       static singleton& instance() {
       static singleton& instance() {
               static singleton s;
               static singleton s;
               return s;
               return s;
       }
       }
       int check() {return initialized;}
       int check() {return initialized;}
private:
private:
       singleton() : initialized(1) {
       singleton() : initialized(1) {
               if ( counter++ == 0 ) throw "just for the heck of it";
               if ( counter++ == 0 ) throw "just for the heck of it";
               initialized = 2;
               initialized = 2;
       }
       }
       singleton( const singleton& rhs );
       singleton( const singleton& rhs );
       void operator=( const singleton& rhs );
       void operator=( const singleton& rhs );
       int initialized;
       int initialized;
       static int counter;
       static int counter;
};
};
int singleton::counter;
int singleton::counter;
int main()
int main()
{
{
       while (1) {
       while (1) {
               try {
               try {
                       return singleton::instance().check()-2;
                       return singleton::instance().check()-2;
               } catch (...) { }
               } catch (...) { }
       }
       }
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.