Search code examples
c++visual-studio-2017compiler-warningssetjmp

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"?


Solution

  • 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...