+Fri Jul 10 10:02:03 1998 Klaus-Georg Adams <Klaus-Georg.Adams@chemie.uni-karlsruhe.de>
+
+ * g++.other/singleton.C: New test. Warning is under dispute.
+ Runtime crash is not.
+
Thu Jul 9 23:07:45 1998 Martin von Loewis <martin@mira.isdn.cs.tu-berlin.de>
* g++.ns/{alias2.C, alias5.C, koenig4.C, lookup3.C ns13.C,
--- /dev/null
+// This tests two things:
+// 1. there is an annoying warning. singleton.C:27: warning: `class
+// singleton' only defines private constructors and has no friends egcs
+// fails to see that there is a public static accessor function.
+// 2. the program crashes, because apparently the static variable s in
+// singleton::instance() is considered constructed although the ctor
+// exited via an exception.
+
+class singleton {
+public:
+ static singleton& instance() {
+ static singleton s;
+ return s;
+ }
+ ~singleton() { delete sigsegv; }
+ int crash() { return *sigsegv; }
+
+private:
+ singleton() : sigsegv(0) {
+ if ( counter++ == 0 ) throw "just for the heck of it";
+ sigsegv = new int(0);
+ }
+ singleton( const singleton& rhs );
+ void operator=( const singleton& rhs );
+ int* sigsegv;
+ static int counter;
+};
+
+int singleton::counter;
+
+int main()
+{
+ while (1) {
+ try {
+ return singleton::instance().crash();
+ } catch (...) { }
+ }
+}