Interix (SUA) by default does not call destructors, but in x86 mode, does have an option for it.
Taking this test program, saved as test.cc
:
#include <stdio.h>
#include <setjmp.h>
struct A {
~A() { puts("~A"); }
};
jmp_buf buf;
void f() {
A a;
longjmp(buf, 1);
}
int main() {
if (setjmp (buf))
return 0;
f();
}
here's how Interix behaves. For brevity, I've omitted the required proper setup of PATH
.
$ cc -mx86 test.cc && ./a.out
$ cc -mx86 -X /EHa test.cc && ./a.out
cl : Command line warning D9025 : overriding '/EHs' with '/EHa'
~A
$ cc -mamd64 test.cc && ./a.out
$ cc -mamd64 -X /EHa test.cc && ./a.out
cl : Command line warning D9025 : overriding '/EHs' with '/EHa'
$
The comments suggest that cc -X /EHa
does not conform to POSIX, for example because /EHa
would catch signals. That is not entirely true:
$ cat test.cc
#include <signal.h>
int main() {
try {
raise(SIGFPE);
} catch (...) {
// ignore
}
}
$ cc -mx86 -X /EHa test.cc && ./a.out
cl : Command line warning D9025 : overriding '/EHs' with '/EHa'
Floating point exception (core dumped)
If I change raise(SIGFPE)
to a division by zero, I do indeed see that the exception handler catches it, but neither POSIX nor C++ requires any particular behaviour for that, so that doesn't affect conformance. It is also not the case that all asynchronous signals are caught: for this program:
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
void sigint(int signal) {
puts("sigint");
exit(0);
}
int main() {
signal(SIGINT, sigint);
try {
for (;;) ;
} catch (...) {
// ignore
}
}
"sigint" is printed after Ctrl-C, as expected. I don't see a reason for claiming that this implementation fails to meet POSIX requirements.
longjmp
. – Oakumlongjmp()
's purpose to do something like exception processing before exception did exist ? – Mudstone/EH
. – Eatssetjmp
/longjmp
on code where unwinding would call non-trivial destructors causes undefined behavior. – Reysetjmp
/longjmp
implementation as what's been discussed as "Windows", which is presumably the normal winapi subsystem. If you could confirm that Interix has this property, that would be a good answer. – Particiaparticipantlongjmp
to unwind, but why exactly? – Stanwin/EHa
, because this feature introduces non-POSIX-compliant behaviour to your program (SEH/signals problems). So, if Interix count, then you won't have another behaviour tosetjmp
/longjmp
, because/EHa
will make your program incompatible with POSIX? There are always two sides of a medal. The system, that supports compliance and the program, that uses compliance. – Afterbody