Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSVC warning 4611 regarding setjmp w/POD struct

Trying to turn up some warning levels on a C codebase that also builds as C++. I'm giving Visual Studio a shot (for some reason).

Got a warning about setjmp interactions, despite not seeing any relevant destructors. so I did a test:

#include <setjmp.h>

struct X { int y; };

int main() {
    struct X x;

    jmp_buf buf;
    if (setjmp(buf) == 0) {
        longjmp(buf, 1);
    } else {
        // whatever.
    }
}

Enabling the warning on the command-line:

C:\wherever>cl /we4611 test.cpp

test.cpp test.cpp(9): error C4611: interaction between '_setjmp' and C++ object destruction is non-portable

This seems like an extremely useful warning--if it was warning me about crossing C++ destructor code. But that's a POD type. There shouldn't be any destructor code.

Am I missing something here, or did they botch this warning to the point of making it basically "you used setjmp in a C++ program"?

like image 568
HostileFork says dont trust SE Avatar asked Jan 24 '26 15:01

HostileFork says dont trust SE


1 Answers

did they botch this warning to the point of making it basically "you used setjmp in a C++ program"?

Looks to be the case.

I'd probably classify it as a bug, myself. But it was easier to make a suggestion on the Microsoft website. Suggestions can be voted on, there...

like image 162
HostileFork says dont trust SE Avatar answered Jan 27 '26 04:01

HostileFork says dont trust SE



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!