public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* inline operator delete redefinition and in-charge deleting destructor
@ 2004-05-11 14:19 Christian BRUEL
  2004-05-11 15:55 ` Eljay Love-Jensen
  2004-05-12  4:08 ` llewelly
  0 siblings, 2 replies; 8+ messages in thread
From: Christian BRUEL @ 2004-05-11 14:19 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: inline operator delete redefinition and in-charge deleting destructor
  2004-05-11 14:19 inline operator delete redefinition and in-charge deleting destructor Christian BRUEL
@ 2004-05-11 15:55 ` Eljay Love-Jensen
  2004-05-11 16:10   ` Jonathan Wakely
  2004-05-12  4:08 ` llewelly
  1 sibling, 1 reply; 8+ messages in thread
From: Eljay Love-Jensen @ 2004-05-11 15:55 UTC (permalink / raw)
  To: Christian BRUEL, gcc-help

Hi Christian.

You need...
#include "new"
... at the top of your i.h file.

Also, destructors have () parameter specification, not (void) for their 
parameters.

Also, your header files should have guards to make sure they are only 
included once.

Also, C++ uses...
#include <cstdio>
... not...
#include <stdio.h>

Also, you may want to change the name of your "new" header file to 
"mynew.h" or "mynew.hxx" or "mynew.hpp".  I prefer the first convention.

Style point:  MyClass* b = new MyClass; (the C++ way) is preferable to 
MyClass *b = new MyClass; (the C way).

Style point:  you should put the "extern int glob;" in a header file, 
instead of hard coded.

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: inline operator delete redefinition and in-charge deleting destructor
  2004-05-11 15:55 ` Eljay Love-Jensen
@ 2004-05-11 16:10   ` Jonathan Wakely
  2004-05-11 16:27     ` Eljay Love-Jensen
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Wakely @ 2004-05-11 16:10 UTC (permalink / raw)
  To: gcc-help


> Also, destructors have () parameter specification, not (void) for their 
> parameters.

That's a matter of style, they mean the same thing and are equally valid.

> Also, C++ uses...
> #include <cstdio>
> ... not...
> #include <stdio.h>

Again, both are valid.

jon


-- 
"A great many people think they are thinking when they are merely
 rearranging their prejudices."
	- William James

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: inline operator delete redefinition and in-charge deleting destructor
  2004-05-11 16:10   ` Jonathan Wakely
@ 2004-05-11 16:27     ` Eljay Love-Jensen
  2004-05-12  3:50       ` llewelly
  0 siblings, 1 reply; 8+ messages in thread
From: Eljay Love-Jensen @ 2004-05-11 16:27 UTC (permalink / raw)
  To: Jonathan Wakely, gcc-help

Hi Jon,

 >That's [(void) for the destructor] a matter of style, they mean the same 
thing and are equally valid.

I believe that is incorrect*, and that they are explicitly invalid for 
destructors and default constructors.

They are optional for other member methods, and typically in C++ are omitted.

 >Again, both [<stdio.h> and <cstdio>] are valid.

I believe that is incorrect*.  In C the header file is <stdio.h>, whereas 
in C++ <cstdio> is the header file.

Sincerely,
--Eljay

* I may be mistaken.  I'd have to review the ISO 14882 spec to be sure.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: inline operator delete redefinition and in-charge deleting destructor
  2004-05-11 16:27     ` Eljay Love-Jensen
@ 2004-05-12  3:50       ` llewelly
  0 siblings, 0 replies; 8+ messages in thread
From: llewelly @ 2004-05-12  3:50 UTC (permalink / raw)
  To: Eljay Love-Jensen; +Cc: Jonathan Wakely, gcc-help

Eljay Love-Jensen <eljay@adobe.com> writes:

> Hi Jon,
> 
>  >That's [(void) for the destructor] a matter of style, they mean the
> same thing and are equally valid.
> 
> I believe that is incorrect*, and that they are explicitly invalid for
> destructors and default constructors.
> 
> They are optional for other member methods, and typically in C++ are omitted.
> 
>  >Again, both [<stdio.h> and <cstdio>] are valid.
> 
> I believe that is incorrect*.  In C the header file is <stdio.h>,
> whereas in C++ <cstdio> is the header file.

See D.5/1, table 100 . <stdio.h> is deprecated, but still normative. I
    doubt it will ever be removed, unless C merges with C++, which
    seems unlikely.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: inline operator delete redefinition and in-charge deleting destructor
  2004-05-11 14:19 inline operator delete redefinition and in-charge deleting destructor Christian BRUEL
  2004-05-11 15:55 ` Eljay Love-Jensen
@ 2004-05-12  4:08 ` llewelly
  1 sibling, 0 replies; 8+ messages in thread
From: llewelly @ 2004-05-12  4:08 UTC (permalink / raw)
  To: Christian BRUEL; +Cc: gcc-help

Christian BRUEL <christian.bruel@st.com> writes:

> 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

'new' is a standard C++ library header. if you re-define it, the
    behavior is undefined.

If you aren't trying to re-implemtn part of the C++ standard library,
    you have no business naming a header file 'new'.

Otherwise, investigate -nostdinc++, see: http://xrl.us/b2qw
[snip]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: inline operator delete redefinition and in-charge deleting destructor
  2004-05-11 19:12 Christian Bruel
@ 2004-05-11 19:39 ` Eljay Love-Jensen
  0 siblings, 0 replies; 8+ messages in thread
From: Eljay Love-Jensen @ 2004-05-11 19:39 UTC (permalink / raw)
  To: Christian Bruel, gcc-help, gcc-bugs

Hi Christian,

Keep in mind that inlined routines must be visible in all compilation units 
in which they are used.

Sincerely,
--Eljay

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: inline operator delete redefinition and in-charge deleting destructor
@ 2004-05-11 19:12 Christian Bruel
  2004-05-11 19:39 ` Eljay Love-Jensen
  0 siblings, 1 reply; 8+ messages in thread
From: Christian Bruel @ 2004-05-11 19:12 UTC (permalink / raw)
  To: eljay, gcc-help, gcc-bugs

including "new" in i.h will certainly make the example work (and would 
certainly be of better style), but I would like to know if it is just a 
workaround in order to comply with the new C++ ABI or is it mandatory by the 
langage ? 

The compiler generates implicit calls to "delete", so the programmer is not 
faulty not have included the "delete" definition in ddef.cxx.

The real problem is that I have a very different behavior in case "delete" is 
not inlined (e.g heuristic decided not to), because this way my "delete" 
contribution becomes externally visible, in particular from the 
deleting-destructor. I don't think that "inline" should change the semantic 
of a program when not unspecified.

Would it be possible in order to to fix this behavior that the compiler always 
emits the function body of inlined memory operators, the rational is that the 
compiler might instantiate calls to those and need the contribution ? (To: 
gcc-bugs)

Best Regards and thanks,

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


----- Original Message ----- 
From: "Eljay Love-Jensen" <eljay@adobe.com>
To: "Christian BRUEL" <christian.bruel@st.com>; <gcc-help@gcc.gnu.org>
Sent: Tuesday, May 11, 2004 5:54 PM
Subject: Re: inline operator delete redefinition and in-charge deleting
destructor


> Hi Christian.
>
> You need...
> #include "new"
> ... at the top of your i.h file.
>
> Also, destructors have () parameter specification, not (void) for their
> parameters.
>
> Also, your header files should have guards to make sure they are only
> included once.
>
> Also, C++ uses...
> #include <cstdio>
> ... not...
> #include <stdio.h>
>
> Also, you may want to change the name of your "new" header file to
> "mynew.h" or "mynew.hxx" or "mynew.hpp".  I prefer the first convention.
>
> Style point:  MyClass* b = new MyClass; (the C++ way) is preferable to
> MyClass *b = new MyClass; (the C way).
>
> Style point:  you should put the "extern int glob;" in a header file,
> instead of hard coded.
>
> HTH,
> --Eljay
>
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-05-12  4:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-11 14:19 inline operator delete redefinition and in-charge deleting destructor Christian BRUEL
2004-05-11 15:55 ` Eljay Love-Jensen
2004-05-11 16:10   ` Jonathan Wakely
2004-05-11 16:27     ` Eljay Love-Jensen
2004-05-12  3:50       ` llewelly
2004-05-12  4:08 ` llewelly
2004-05-11 19:12 Christian Bruel
2004-05-11 19:39 ` Eljay Love-Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).