-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Allow assert() with custom error message #1303
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
Comments
I believe this is related to #1304. One consideration here is whether the assert is going to invoke |
There's precedent for such a desirable feature. Long, long ago someone came up with an idea of advanced assert in C++. Basically, when assert fires, it could also print multiple interesting values. It was very clever, but unfortunately, it severely impacted compilation time, so the effort to get it into Boost was abandoned. Some notes about Zig implementation:
|
This is solved in c2db077 which makes the distinction between |
Many other languages allow adding a custom error message to assertions, to provide better context if the assertion fails. For example:
I've been finding myself missing this in Zig. I don't know whether it's possible to support both
assert(cond)
andassert(cond, fmt, ...)
with the same function name, but if not, then we could have, say,assert(cond)
andassertMsg(cond, fmt, ...)
.The text was updated successfully, but these errors were encountered: