aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus-Georg Adams <Klaus-Georg.Adams@chemie.uni-karlsruhe.de>1998-07-10 08:03:35 +0000
committerRobert Lipe <robertl@gcc.gnu.org>1998-07-10 08:03:35 +0000
commit1d8cc6e9f4f38563dd8db645641706d57098866e (patch)
tree3437a183b759b69f84e1627b5254793f4f438828
parent03c5634a9d1c7bf019f539770fe4a16304315402 (diff)
downloadgcc-1d8cc6e9f4f38563dd8db645641706d57098866e.zip
gcc-1d8cc6e9f4f38563dd8db645641706d57098866e.tar.gz
gcc-1d8cc6e9f4f38563dd8db645641706d57098866e.tar.bz2
singleton.C: New test.
* g++.other/singleton.C: New test. Warning is under dispute. Runtime crash is not. From-SVN: r21050
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.old-deja/g++.other/singleton.C38
2 files changed, 43 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 249483d..9fe92bd 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+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,
diff --git a/gcc/testsuite/g++.old-deja/g++.other/singleton.C b/gcc/testsuite/g++.old-deja/g++.other/singleton.C
new file mode 100644
index 0000000..32722c3
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.other/singleton.C
@@ -0,0 +1,38 @@
+// 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 (...) { }
+ }
+}