Fix #14195 Show warning when main() throws an exception#7887
Fix #14195 Show warning when main() throws an exception#7887chrchr-github merged 10 commits intodanmar:mainfrom
Conversation
|
Do we need to do something with the new id? |
Beside triggering it from |
|
|
||
| void CheckExceptionSafety::entryPointThrowError(const Token * const tok) | ||
| { | ||
| reportError(tok, Severity::error, "throwInEntryPoint", "Exception thrown in function that is an entry point.", CWE398, Certainty::normal); |
There was a problem hiding this comment.
I suggest something like:
Unhandled exception is thrown in function that is an entry point.
We only warn if it's unhandled right?
This is undefined behavior right? To throw an exception that is not catched..
There was a problem hiding this comment.
Throwing in main() results in program termination: https://en.cppreference.com/w/cpp/language/throw.html
I'll add a negative test.
There was a problem hiding this comment.
ok so it's defined behavior. It's not 100% clear to me that it should have "error" severity or if "warning" / "portability" would be more proper.
If program termination is wanted this is not a bad option to achieve that. However there is a danger that some RAII classes will not be destroyed properly. And using some std::exit function or something like that could be more clear about the intent.
There was a problem hiding this comment.
It looks like the outcome is the same as for throwing from a noexcept function, so the severity should also be the same.
I suggest something like:
Unhandled exception is thrown in function that is an entry point.
Should we change the message for throwInNoexceptFunction as well?
There was a problem hiding this comment.
It looks like the outcome is the same as for throwing from a noexcept function, so the severity should also be the same.
I agree .. it's not 100% clear to me so well we can keep it as is.
There was a problem hiding this comment.
Should we change the message for throwInNoexceptFunction as well?
please feel free to do it because it's only when it's not handled it's a problem. A user might think we sloppily warn whenever exceptions are thrown.
|
I would like that the PR title and ticket are a bit more descriptive. If we will look in the git log later we might wonder if this prevents Cppcheck from throwing some exceptions in main(). |
|



No description provided.