* auto-profile.c (afdo_annotate_cfg): Use update_max_bb_count.
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.other / singleton.C
blob2a27ca3cd8ef649ed2db939b7c73cffed32bb70e
1 // { 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)
10 class singleton {
11 public:
12        static singleton& instance() {
13                static singleton s;
14                return s;
15        }
16        int check() {return initialized;}
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 };  
29 int singleton::counter;
31 int main()
33        while (1) {
34                try {
35                        return singleton::instance().check()-2;
36                } catch (...) { }
37        }