Skip to content

ASSERT or variant returning result of the expression (not just left-hand operand) #101

@NyanSten

Description

@NyanSten

Hi,

One thing that I currently use pretty often (especially for networking code) is:

if (!AssertTrue(a > 3)) {
    // Handle the failed assertion in release
    return;
}

This allows crashing in debug builds during testing but handling it without crashing for users in release builds.

It looks very similar to:

if (!ASSERT_VAL(a > 3))

but ASSERT_VAL returns the value of a, not the result of the whole expression a > 3.

Obviously it's possible to do

if (ASSERT_VAL(a > 3) <= 3)

but that makes it complicated and error-prone.

Would it be possible to return the result of the whole expression from ASSERT, or to create a variant of the macro (e.g. ASSERT_THAT) that returns the result?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions