Skip to content

Commit

Permalink
document that asserts might not be running at certain optimization le…
Browse files Browse the repository at this point in the history
…vels (#25610)
  • Loading branch information
KristofferC authored and JeffBezanson committed Jan 22, 2018
1 parent 23ea201 commit e0c5d2d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,8 @@ Deprecated or removed
* `rand(t::Tuple{Vararg{Int}})` is deprecated in favor of `rand(Float64, t)` or `rand(t...)`;
`rand(::Tuple)` will have another meaning in the future ([#25429], [#25278]).

* The `assert` function (and `@assert` macro) have been documented that they are not guaranteed to run under various optimization levels and should therefore not be used to e.g. verify passwords.

* `ObjectIdDict` has been deprecated in favor of `IdDict{Any,Any}` ([#25210]).

* `gc` and `gc_enable` have been deprecated in favor of `GC.gc` and `GC.enable` ([#25616]).
Expand Down
14 changes: 14 additions & 0 deletions base/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ systemerror(p, b::Bool; extrainfo=nothing) = b ? throw(Main.Base.SystemError(str
Throw an [`AssertionError`](@ref) if `cond` is `false`.
Also available as the macro [`@assert`](@ref).
!!! warning
An assert might be disabled at various optimization levels.
Assert should therefore only be used as a debugging tool
and not used for authentication verification (e.g. verifying passwords),
nor should side effects needed for the function to work correctly
be used inside of asserts.
"""
assert(x) = x ? nothing : throw(AssertionError())

Expand All @@ -122,6 +129,13 @@ assert(x) = x ? nothing : throw(AssertionError())
Throw an [`AssertionError`](@ref) if `cond` is `false`. Preferred syntax for writing assertions.
Message `text` is optionally displayed upon assertion failure.
!!! warning
An assert might be disabled at various optimization levels.
Assert should therefore only be used as a debugging tool
and not used for authentication verification (e.g. verifying passwords),
nor should side effects needed for the function to work correctly
be used inside of asserts.
# Examples
```jldoctest
julia> @assert iseven(3) "3 is an odd number!"
Expand Down

0 comments on commit e0c5d2d

Please sign in to comment.