-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix #14195 Show warning when main() throws an exception #7887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
chrchr-github
merged 10 commits into
cppcheck-opensource:main
from
chrchr-github:chr_14195
Oct 27, 2025
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f6f8dc1
Update checkexceptionsafety.cpp
chrchr-github 260532b
Update checkexceptionsafety.h
chrchr-github 999350f
Update testexceptionsafety.cpp
chrchr-github a5e9287
Update checkexceptionsafety.cpp
chrchr-github e369865
Format
chrchr-github 83217b8
Format
chrchr-github 8fe787f
Update checkexceptionsafety.cpp
chrchr-github 3269329
Update checkexceptionsafety.cpp
chrchr-github 8ab4575
Add test
web-flow 2133a5d
Improve error message
web-flow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest something like:
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwing in
main()results in program termination: https://en.cppreference.com/w/cpp/language/throw.htmlI'll add a negative test.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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::exitfunction or something like that could be more clear about the intent.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the outcome is the same as for throwing from a
noexceptfunction, so the severity should also be the same.Should we change the message for
throwInNoexceptFunctionas well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree .. it's not 100% clear to me so well we can keep it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.