@@ -296,26 +296,34 @@ void CheckExceptionSafety::nothrowThrows()
296296 if (!function)
297297 continue ;
298298
299+ bool isNoExcept = false , isEntryPoint = false ;
300+
299301 // check noexcept and noexcept(true) functions
300302 if (function->isNoExcept ()) {
301- const Token *throws = functionThrows (function);
302- if (throws)
303- noexceptThrowError (throws);
303+ isNoExcept = true ;
304304 }
305305
306306 // check throw() functions
307307 else if (function->isThrow () && !function->throwArg ) {
308- const Token *throws = functionThrows (function);
309- if (throws)
310- noexceptThrowError (throws);
308+ isNoExcept = true ;
311309 }
312310
313311 // check __attribute__((nothrow)) or __declspec(nothrow) functions
314312 else if (function->isAttributeNothrow ()) {
315- const Token *throws = functionThrows (function);
316- if (throws)
313+ isNoExcept = true ;
314+ }
315+ else if (mSettings ->library .isentrypoint (function->name ())) {
316+ isEntryPoint = true ;
317+ }
318+ if (!isNoExcept && !isEntryPoint)
319+ continue ;
320+ if (const Token* throws = functionThrows (function)) {
321+ if (isEntryPoint)
322+ entryPointThrowError (throws);
323+ else
317324 noexceptThrowError (throws);
318325 }
326+
319327 }
320328}
321329
@@ -324,6 +332,11 @@ void CheckExceptionSafety::noexceptThrowError(const Token * const tok)
324332 reportError (tok, Severity::error, " throwInNoexceptFunction" , " Exception thrown in function declared not to throw exceptions." , CWE398, Certainty::normal);
325333}
326334
335+ void CheckExceptionSafety::entryPointThrowError (const Token * const tok)
336+ {
337+ reportError (tok, Severity::error, " throwInEntryPoint" , " Exception thrown in function that is an entry point." , CWE398, Certainty::normal);
338+ }
339+
327340// --------------------------------------------------------------------------
328341// void func() { functionWithExceptionSpecification(); }
329342// --------------------------------------------------------------------------
0 commit comments