-
Notifications
You must be signed in to change notification settings - Fork 743
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
enforcement for no-throw finally actions #1191
base: main
Are you sure you want to change the base?
Conversation
because the gsl::final_action destructor is marked noexcept(true), the action cannot throw else the program will terminate; this nuance should be documented explicitly and (to be investigated later) ideally enforced in code.
a throwing finally action will be accepted by the compiler but result in surprise termination at runtime; enforce that actions provided to finally must be non-throwing at compile time.
note: this could constitute a breaking change for current users of gsl::finally that use it with (questionably) throwing functions, or at least functions not known to the compiler to be not throwing. So follow up discussion if we agree this enforcement is good (seems ostensibly better than the compiler allowing the throwing functions and then terminating later at runtime when they throw), is whether and how much to ease back-compat integration. Either require users to mark-up code with noexcept or offer a less-pain onramp like using SFINAE or tag struct to allow temp silencing of warning. |
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.
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
Files not reviewed (1)
- include/gsl/util: Language not supported
@microsoft-github-policy-service agree company="Microsoft" |
Note I have companion PRs here: This PR is additive to The different PRs are meant to gauge which the community best likes. In all 3 PRs the same problem we want to address is that gsl finally makes it too easy to write code that would cause surprise crashes at runtime. |
pending discussion of #1193 |
a throwing finally action will be accepted by the compiler but result in surprise termination at runtime; enforce that actions provided to finally must be non-throwing at compile time.