public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* Re: inline operator delete redefinition and in-charge deleting destructor
@ 2004-05-12 16:35 Christian Bruel
2004-05-12 17:20 ` Eljay Love-Jensen
0 siblings, 1 reply; 2+ messages in thread
From: Christian Bruel @ 2004-05-12 16:35 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] 2+ messages in thread
* Re: inline operator delete redefinition and in-charge deleting destructor
2004-05-12 16:35 inline operator delete redefinition and in-charge deleting destructor Christian Bruel
@ 2004-05-12 17:20 ` Eljay Love-Jensen
0 siblings, 0 replies; 2+ messages in thread
From: Eljay Love-Jensen @ 2004-05-12 17:20 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] 2+ messages in thread
end of thread, other threads:[~2004-05-11 19:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-12 16:35 inline operator delete redefinition and in-charge deleting destructor Christian Bruel
2004-05-12 17:20 ` 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).