enforcement for no-throw finally actions#1191
enforcement for no-throw finally actions#1191apenn-msft wants to merge 4 commits intomicrosoft:mainfrom
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. |
@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.