From: horst DOT kraemer AT snafu DOT de (Horst Kraemer) Newsgroups: comp.os.msdos.djgpp Subject: Re: How can I tell if it's a bug from DJGPP or GCC? Date: Tue, 22 Sep 1998 21:24:09 GMT Organization: [Posted via] Interactive Networx Lines: 63 Message-ID: <36080bfd.411106352@news.snafu.de> References: <6u7smk$9t7$1 AT nnrp1 DOT dejanews DOT com> <36078819 DOT 377336654 AT news DOT snafu DOT de> <3607D133 DOT E01E67CD AT dds DOT nl> NNTP-Posting-Host: n34-173.berlin.snafu.de To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk On Tue, 22 Sep 1998 18:32:51 +0200, DougEleveld wrote: >> >Bug: >> >The static singleton is within the scope of class and should be able to be >> >destructed, but DJGPP is trying to destroy it at global scope. >> >*/ >> >> The scope of the declaration has nothing to do with scope of >> "destruction". The scope of "contruction" of singelton::instance is >> the scope of the class by definition. The scope of destruction is the >> scope of the definition - i.e. global scope. The d'tor is not >> accessible at global scope. >So you are saying that a static instance of a class does not have access >to it's own private constructors/destructors? Of course _it_ has not. Only member functions of the class have access to private member functions of the class. Only a (possibly static) member function of singelton could legally destroy it by calling instance.singelton::~singelton(); Destruction is done _via_ a member function ~singelton(), but the problem is: who has the right to evoke this private member function singelton::~singelton ? It doesn't evoke "itself". Formally the static 'instance' defined at file level is destroyed by the run time system by a call singelton::instance.~singelton(); alias singelton::instance.singelton::~singelton(); at the end of the program. As this formal call is not performed _by_ a member function of singelton, singelton::~singleton() is not accessible at this point. The "executor" of this formal call is formally treated as inline code at file level with normal acess restrictions and therefore the definition of 'instance' is flagged as an error by _every_ c++ compiler I know of if a non-public dtor is defined. This example struct X { protected : /* or private */ ~X() {} }; void f() { X x; } would yield a syntax error, too, because the run time system has no access to the d'tor if it would have to destroy x when it goes out of scope. I think this is exactly the same case. Regards Horst