Compile with -DNO_ASSERTIONS to turn assertions off
Use case 1
Pass the optional success argument & check for false return value as an indication of assertion failure: use assertions_interface, only : assert,assertions if (assertions) call assert( 2 > 1, "always true inequality", success) if (error_code/=0) call my_error_handler()
Use case 2
Error-terminate if the assertion fails: use assertions_interface, only : assert,assertions if (assertions) call assert( 2 > 1, "always true inequality")
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| logical, | public, | parameter | :: | assertions | = | .false. | |
| integer, | public, | parameter | :: | max_errmsg_len | = | len("warning (183): FASTMEM allocation is requested but the libmemkind library is not linked in, so using the default allocator.") | longest Intel compiler error messagea (see https://intel.ly/35x84yr). |
Report on the truth of an assertion or error-terminate on assertion failure
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| logical, | intent(in) | :: | assertion | Most assertions will be expressions, e.g., call assert( i>0, "positive i") |
||
| character(len=*), | intent(in) | :: | description | Brief statement of what is being asserted |
||
| class(*), | intent(in), | optional | :: | diagnostic_data | Optional assertion result |
|
| logical, | intent(out), | optional | :: | success | Optional assertion result |