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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [testsuite/] [g++.old-deja/] [g++.other/] [singleton.C] - Blame information for rev 199

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 149 jeremybenn
// { dg-do run  }
2
// This tests two things:
3
// 1. there is an annoying warning.
4
// singleton.C:26: warning: `class singleton' only defines private constructors and has no friends
5
// egcs fails to see that there is a public static accessor function.
6
// 2. the program crashes, because apparently the static variable s in
7
// singleton::instance() is considered constructed although the ctor
8
// exited via an exception. (crash changed to nonzero return here)
9
 
10
class singleton {
11
public:
12
       static singleton& instance() {
13
               static singleton s;
14
               return s;
15
       }
16
       int check() {return initialized;}
17
 
18
private:
19
       singleton() : initialized(1) {
20
               if ( counter++ == 0 ) throw "just for the heck of it";
21
               initialized = 2;
22
       }
23
       singleton( const singleton& rhs );
24
       void operator=( const singleton& rhs );
25
       int initialized;
26
       static int counter;
27
};
28
 
29
int singleton::counter;
30
 
31
int main()
32
{
33
       while (1) {
34
               try {
35
                       return singleton::instance().check()-2;
36
               } catch (...) { }
37
       }
38
}
39
 

powered by: WebSVN 2.1.0

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