When should value parameters be destroyed?

Martin von Loewis loewis at informatik.hu-berlin.de
Sun Oct 1 18:11:48 UTC 2000


[gcc does indeed manage to put the destructor outside of the
function-try-block]

> I would prefer not to, given the space advantage of the current
> strategy, but I'm willing to go along if others feel that this is the
> best way to go.

I agree it would be a good solution if it would work, but let me try
to come up with more counter-examples. Consider

--- a.h ----
struct A{
  inline ~A();
};

void foo(A a);

--- a.cc ---
#include "a.h"

void foo(A a){}

--- b.cc ---
#include "a.h"

inline A::~A(){}

int main(){
  A a;
  foo(a);
}

------------

I believe a.cc and b.cc together are a well-formed program. Even
though C++ requires that inline functions are defined when they are
"used", A::~A does not need to be defined when compiling a.cc - the
destructor is not "used" inside foo.

Yet, when compiling b.cc, gcc sees that it can inline the destructor
in all places (namely, destruction of A::a), and does not emit it
out-of-line. As a result, I get

pandora loewis 662 ( ~/tmp ) > g++ -o a -O2 a.cc b.cc
/var/tmp/ccD7ikdu.o: In function `foo(A)':
/var/tmp/ccD7ikdu.o(.text+0x8): undefined reference to `A::~A(void)'
collect2: ld returned 1 exit status

Would you agree that this example should compile (even though any sane
developer would not rely on the mechanism in a real application)? If
so, how would you propose that the ABI deals with it?

Regards,
Martin





More information about the cxx-abi-dev mailing list