-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Do something about @assert
#51729
Comments
Because it can be removed by "various" optimisation levels (would be good to document) it is possible to have it present for debugging runs, but removed from production runs without editing the source. So the test can be expensive as it is only present in debugging runs. But that means it is intentionally not suitable for any use-case where a permanent test is required, so it cannot be relied on to provide any of the cases in the OP. An equivalent non-removable convenience macro ( Edit: I recently came across the same problem recently in a C++ case where code was using assert to check and then production builds failed to validate inputs. |
Nay, |
Then the docs for assert are wrong. It is actually probably good that it does not remove by optimisation, makes debugging optimised builds difficult, might be good to have an |
The docs say it may be removed, that it doesn't yet is something that may be changed, see eg #37874 |
And as been said, this is a debugging tool to check that internal invariant are upheld so it isn't suitable for 1 or 3. 2a would be solved with something like the PR I linked above. I think this issue can be closed since there doesn't really seem to be anything actionable to do here. |
I want to take exactly one of the following actions: I don't like the status quo of threatening to disable |
It leads to bad programming practices as well, where people refuse to add |
Well yes, if the checks are necessary you should be using something else than an assert. Doing something like
wouldn't be a good idea. |
Which is why I suggested adding There should also be the ability to manually enable/disable
so the user can know its tested in debugging even at maximum optimisation, and know it won't slow production even on low optimisation. |
+1 that it would actually be a super nice feature if I could put |
I think there should be 3 separate functions for these three separate needs (eg I gave adding |
@ericphanson What does |
Item (2) from the OP; a check that is only guaranteed to run in a debug mode or such. (basically the current one but we should also let the compiler skip it if advantageous and are not in a debug mode) |
xref #10614 |
@assert
seems like a pretty useless macro right now.Here are some plausible uses for
@assert
a. When small constant factors do matter
b. When small constant factors do not matter
Right now
@assert
is only useful in 2.b.The text was updated successfully, but these errors were encountered: