This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
inline operator delete redefinition and in-charge deleting destructor
- From: Christian BRUEL <christian dot bruel at st dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Tue, 11 May 2004 14:59:01 +0200
- Subject: inline operator delete redefinition and in-charge deleting destructor
- Organization: STMicroelectronics
I have the following problem with gcc3.3.3 on Solaris:
If providing the definition of a destructor outside the module where
"delete" is called, the compiler instantiates a function call to delete
to the standard library, thus missing my definition.
See the following program:
Of course, I comment out the "#include "new"" in ddef.cxx the program
works.
Similarly if I don't inline the operator delete I get a correct
behavior.
Do I miss something ? is it a problem with the "inline" keyword that
don't provide a definition preempting the one from the library ?
Shouldn't inlined functions provide their body in case they are not
member functions ?
Does the "language" forces me to include "new" for every implicit call
to memory operators ?
Thank you,
--- i.h ---
class MyClass
{
public:
virtual ~MyClass(void);
};
--- new ---
extern int glob;
inline void operator delete(void *p)
{
glob++;
}
--- ddef.cxx ---
#include "i.h"
MyClass::~MyClass(void)
{
}
--- foo.cxx ---
#include <stdio.h>
#include "i.h"
// explicit call to delete. include definition
#include "new"
int glob;
main()
{
MyClass *b = new MyClass;
delete b;
if (glob != 1)
printf ("FAILED %d\n", glob);
else
printf ("SUCCESS\n");
}