CERT.MSC.NORETURN_FUNC_RETURNS
Do not return from a function declared [[noreturn]].
Vulnerability and risk
Returning from a function marked [[noreturn]] results in undefined behavior that might be exploited to cause data-integrity violations.
Mitigation and prevention
Do not return from a function declared [[noreturn]].
Example
Copy
#include <cstdlib>
[[noreturn]] void f1(int i) {
if (i > 0)
throw "Received positive input";
else if (i < 0) {
//std::exit(0);
i++;
}
}
[[noreturn]] void f2(int i) {
if (i > 0)
throw "Received positive input";
std::exit(0);
}