Visual C ++ error: function should return value

I am working on a multi-platform project, and on some platforms there are disabled functions, and in the interface for these functions I usually do the following:

bool Foo::bar() const {
    // disabled
    abort();
}

GCC / LLVM do not require non-void functions to return values ​​(they just give a warning), and in this case, when I call abort(), they are smart enough to not even give warnings (since the function will never return).

Is there a way (compile a flag?) To force Visual C ++ 2010 to behave the same, so I am not breaking the build of Windows? I know that I can always return a value after an interrupt, but when working on other platforms, I usually forget about it, and behavior that does not give an error seems more appropriate.

+5
source share
3 answers

How do you want to disable the error, add /w34716as a compilation flag (provided that you use warning level 3 or higher) - now only a warning is issued (if the warning level is 3 or higher). You can also turn off warning ( /wd4716), but this is probably not a good idea - depending on the number of warnings due to this behavior.

+1
source

__declspec(noreturn) MSV++. , abort ​​ __declspec(noreturn). , , , . abort. __declspec(noreturn), -.

+4

, Visual ++ __declspec(noreturn), , . , .

, , SO. , abort() Visual ++.

+2

All Articles