From mboxrd@z Thu Jan 1 00:00:00 1970 From: knizhnik@cecmow.enet.dec.com To: "egcs-bugs@cygnus.com"@vbormc.vbo.dec.com Subject: Is it a bug ? Date: Mon, 08 Dec 1997 03:17:00 -0000 Message-id: <199712081205.NAA25992@vbormc.vbo.dec.com> X-SW-Source: 1997-12/msg00136.html List-Id: Few days ago I have downloaded egcs and was glad to see that some bugs which were present in GCC 2.7.2 were fixed in EGCS. But I am failed to compile my program (which was compiled with GCC 2.7.2) because of following problem with protected "operator delete": ----------------------------------------------- #include class A { protected: int a; void operator delete(void* p) { ::delete p; } public: void foo() {} void* operator new(size_t size) { return malloc(size); } A() {} // no error if comment this line }; class B : public A { }; main() { B* bp = new B; bp->foo(); } ------------------------------------------------------ bash$ gcc -Wall -v new.cxx Reading specs from /usr/local/lib/gcc-lib/alphaev5-dec-osf4.0/egcs-2.90.21/specs gcc version egcs-2.90.21 971202 (egcs-1.00 release) /usr/local/lib/gcc-lib/alphaev5-dec-osf4.0/egcs-2.90.21/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=90 -Dunix -D__osf__ -D __alpha -D__alpha__ -D_LONGLONG -DSYSTYPE_BSD -D_SYSTYPE_BSD -D__unix__ -D__osf_ _ -D__alpha -D__alpha__ -D_LONGLONG -D__SYSTYPE_BSD__ -D_SYSTYPE_BSD -D__unix -D __SYSTYPE_BSD -Asystem(unix) -Asystem(xpg4) -Acpu(alpha) -Amachine(alpha) -D__EX CEPTIONS -Wall -D__LANGUAGE_C__ -D__LANGUAGE_C -DLANGUAGE_C -D__LANGUAGE_C_PLUS_ PLUS__ -D__LANGUAGE_C_PLUS_PLUS -D__cplusplus new.cxx /tmp/ccaajfaa.ii GNU CPP version egcs-2.90.21 971202 (egcs-1.00 release) #include "..." search starts here: #include <...> search starts here: /usr/local/include/g++ /usr/local/include /usr/local/alphaev5-dec-osf4.0/include /usr/local/lib/gcc-lib/alphaev5-dec-osf4.0/egcs-2.90.21/include /usr/include End of search list. /usr/local/lib/gcc-lib/alphaev5-dec-osf4.0/egcs-2.90.21/cc1plus /tmp/ccaajfaa.i i -quiet -dumpbase new.cc -Wall -version -o /tmp/ccaajfaa.s GNU C++ version egcs-2.90.21 971202 (egcs-1.00 release) (alphaev5-dec-osf4.0) co mpiled by GNU C version egcs-2.90.21 971202 (egcs-1.00 release). new.cxx: In function `int main()': new.cxx:6: `static void A::operator delete(void *)' is protected new.cxx:17: within this context -------------------------------------------------------------------------------- It looks like bug in compiler (if class A has no constructor then no error message is produced). I declare protected "operator delete" to prohibit explicite deallocation of objects of this class. I am is not familiar with last ideas of C++ standard, may be if you are using "operator new" then "operator delete" is also required (to be called if exception was raised within "new"), but in any case how is it possible to prevent user from explicit class deallocation ?