assert() feature request
- Dominant language
- C++
- Stars
- 3k
- Forks
- 352
- PR merge metrics
- No merged PRs in 30d
Description
One handy trick I learned long ago (thanks Mark Leone!) was to do this:
if (failure_case) {
assert(!"Unknown material type")
}
I assume this works because the string resolves to a 'true' which inverted gives the false which triggers the assert. The handy bit is that when the program exits you get:
a.out: blah.cpp:10: int main(): Assertion `!"Unknown material type"' failed.
by which you basically get an assert with a reason / error message in one shot.
ISPC doesn't like the idea of making the string into a bool:
bsdf_demo.ispc:24:21: Error: syntax error, unexpected TOKEN_STRING_LITERAL.
Assert(!"Unknown material type");
Not a big priority request and maybe this would throw off other elements of the language but (IMO) it'd be handy nonetheless.
Contributor guide
Assessment
This issue has not been assessed yet.