Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.

Bug: destructor called twice

dohashi
Beginner
258 Views

Compiling the following on windows with icl or icx with /EHs causes the destructor for the test object to be called twice. 

 

#include <iostream>
#include <csetjmp>

jmp_buf buffer1;
jmp_buf buffer2;

class Test
{
public:
~Test()
{
std::cout << "Test destructor: " << this << std::endl;
}
};

void p2()
{
longjmp( buffer2, 1 );
}

void p1()
{
{
Test test;

if ( setjmp( buffer2 ) == 0 )
{
p2();
}
}

std::cout << "Jumping" << std::endl;
longjmp( buffer1, 1 );
}

int main()
{
if ( setjmp( buffer1 ) == 0 )
{
p1();
}

return 0;
}

This produces the following output:

C:\tmp>icx /EHs intelbug.cpp
Intel(R) oneAPI DPC++/C++ Compiler for applications running on Intel(R) 64, Version 2022.1.0 Build 20220316
Copyright (C) 1985-2022 Intel Corporation. All rights reserved.

C:\tmp>intelbug
Test destructor: 000000595F6FFDA0
Jumping
Test destructor: 000000595F6FFDA0

I know that mixing longjmps with c++ and destructors in particular can be problematic, but I don't think the longjmps should be causing a problem in this case.

This does not happen with VS 2019.

Labels (1)
0 Kudos
1 Reply
ShanmukhS_Intel
Moderator
203 Views

Hi Dohashi,


Thanks for posting on Intel Communities and reporting this issue. We were able to reproduce it on our end and we have informed the development team about it.


We will get back to you soon with an update.


Best Regards,

Shanmukh.SS


Reply