PATCH: Testcase for new C++ bug? Comments please. (COMMITTED)

Robert Lipe robertl@dgii.com
Fri Jul 10 08:32:00 GMT 1998


After private discussion with Klaug-Georg and Martin concluding that the
abort is undisputedly a bug, I've committed this case.

The warning thing is still under debate. :-)

RJL

Klaus-Georg Adams wrote:
> 
> I have come across a new failure of the C++ front-end. However I am
> not completely sure if the program is legal (I think it is, but you
> can try to convince me otherwise).
> 
> The warning which is triggered is bad in any case.
> 
> -- kga
> -------------------------------------------------------------------------
> Klaus-Georg Adams        Email: Klaus-Georg.Adams@chemie.uni-karlsruhe.de
> Institut f. Anorg. Chemie, Lehrstuhl II            Tel: 49(0)721 608 3485
> Universität Karlsruhe, D-76128 Karlsruhe
> -------------------------------------------------------------------------
> 
> --- /dev/null   Mon Jul 18 01:46:18 1994
> +++ gcc/testsuite/g++.old-deja/g++.other/singleton.C        Thu Jul  2 13:03:19 1998
> @@ -0,0 +1,38 @@
> +// This tests two things:
> +// 1. there is an annoying warning.
> +// 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.
> +// 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 (...) { }
> +       }
> +}

-- 
Robert Lipe       http://www.dgii.com/people/robertl       robertl@dgii.com
              (WEB ADDRESS MAY BE TEMPORARILY UNAVAILABLE)





More information about the Gcc-patches mailing list