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

1  #include <cstdlib>
2  
3  [[noreturn]] void f1(int i) {
4  	if (i > 0)
5  		throw "Received positive input";
6  	else if (i < 0) {
7  		//std::exit(0);
8  		i++;
9  		}
10 }
11 
12 [[noreturn]] void f2(int i) {
13   if (i > 0)
14     throw "Received positive input";
15   std::exit(0);
16 }