This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

inline operator delete redefinition and in-charge deleting destructor


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");
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]