[cfe-dev] [Bug] Wrong Exception Handling : Destructor not called immediately

suyog sarda sardask01 at gmail.com
Tue Apr 22 06:02:54 PDT 2014


Thanks to all. I wrote a test case to see if the constructor of outermost
variable completes before destructor of inner temporaries is called.


























*int as;struct a {  a () {  printf("Construct A\n"); }   ~a ()
NOEXCEPT_FALSE { printf("Destruct A\n"); throw 42; }};int f (a const&) {
return 1; }struct b {  b (...) { printf("Construct B\n"); }  ~b ()   {
printf("Destruct B\n"); }   int x(){return 1;}};int main () {  thrown = 0;
try {       printf("%d\n",b(f(a())).x());      }  catch (...) {}}*
Output with clang :








*Construct A Construct B1Destruct BDestruct A*
This indicates that Constructor of outermost object completes before
destructor of inner temporaries is called (as it was able to call function
x() ).

As per the link provided by Richard, it is not yet clear what should be the
order of destructor to be called.
GCC calls destructor of outer local variable as soon as the destructor of
any one of the temporaries throws, destructor of other temporaries are
called later.
This is not easy to achieve in clang with EHStack approach.

Now as we are not sure of the order of destructors to be called, should we
approach with '*full-expression storage duration objects are destroyed
before automatic storage duration objects in all cases*', which would be
achievable with EHStack approach? Because right now, as the destructor of
local variable is not called at all (in our original test case
'init-temp1.C'), there is a resource leak. Or should we wait for things to
get clear and then only go ahead for solving this bug?


-- 
With regards,
Suyog Sarda
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140422/716b26e4/attachment.html>


More information about the cfe-dev mailing list