Skip to content
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

Unconditional assertion that does not cause [[noreturn]] #100

Open
NyanSten opened this issue Aug 22, 2024 · 2 comments
Open

Unconditional assertion that does not cause [[noreturn]] #100

NyanSten opened this issue Aug 22, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@NyanSten
Copy link

Hi and thanks for the amazing library!

For handling unexpected values, I would like an unconditional assertion for which a custom assertion handler can decide not to abort, i.e. one that is not annotated with [[noreturn]]. Something like:

enum_value ToEnum(std::uint8_t byte)
{
    switch (value) {
    case 0x00: return enum_value::first;
    case 0x01: return enum_value::second;
    }
    UNEXPECTED(byte); // Like PANIC(byte) but can continue if the assertion handler does not abort
    return enum_value::unexpected;
}

I want to be able to crash in debug (to make it obvious during testing) but in release, report the value via the assertion handler and continue (to avoid crashing the app for users).

If this is something you'll be interested in as well, I can open a PR for that.

@jeremy-rifkin
Copy link
Owner

Hi, thanks for opening this. I can see the use-case, though the best way to go about this is not entirely clear to me. I'm thinking of questions like does this require maybe-returning variants of both panic and assertions? How could this be clearly introduced without confusion? What would the failure handler interface look like? Maybe some sort of DEBUG_PANIC that's checked in debug and not in release is the solution here?

@NyanSten
Copy link
Author

Well, the assertion handler can already return from fail and the documentation states that it can do that unless it's PANIC or UNREACHABLE so this will be a variant of process_panic but without [[noreturn]] and LIBASSERT_PRIMITIVE_PANIC at the end, like process_assert_fail.

@jeremy-rifkin jeremy-rifkin added the enhancement New feature or request label Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants