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

Split assertion per expressions #3451

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

nobu
Copy link
Member

@nobu nobu commented Jan 29, 2025

Expressions joined with && are better asserted separately, so that it is clear from the failure message which expression is false.

Also, unsigned long may not be enough for ptrdiff_t, e.g., Windows.
Saying that ptrdiff_t can be larger than SIZE_MAX means that PTRDIFF_MAX is larger than SIZE_MAX and ptrdiff_t is sufficient to represent SIZE_MAX, otherwise if PTRDIFF_MAX is smaller than SIZE_MAX, diff will always be smaller than SIZE_MAX as well.
diff could be equal to SIZE_MAX only if PTRDIFF_MAX is equal to SIZE_MAX and these assertions would pass, but I don't think there is any platform where that is the case.

Expressions joined with `&&` are better asserted separately, so that
it is clear from the failure message which expression is false.

Also, `unsigned long` may not be enough for `ptrdiff_t`, e.g., Windows.
Saying that `ptrdiff_t` can be larger than `SIZE_MAX` means that
`PTRDIFF_MAX` is larger than `SIZE_MAX` and `ptrdiff_t` is sufficient
to represent `SIZE_MAX`, otherwise if `PTRDIFF_MAX` is smaller than
`SIZE_MAX`, `diff` will always be smaller than `SIZE_MAX` as well.
`diff` could be equal to `SIZE_MAX` only if `PTRDIFF_MAX` is equal to
`SIZE_MAX` and these assertions would pass, but I don't think there is
any platform where that is the case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant