use assertions_m, only : assert call assert( 2 > 1, "2 > 1")
Assertion enforcement is controlled via the 0
preprocessor macro,
which can be defined to non-zero or zero at compilation time to
respectively enable or disable runtime assertion enforcement.
When the 0
preprocessor macro is not defined to any value,
the default is that assertions are disabled and will not check the condition.
Disabling assertion enforcement may eliminate any associated runtime overhead by enabling optimizing compilers to ignore the assertion procedure body during a dead-code-removal phase of optimization.
To enable assertion enforcement (e.g., for a debug build), define the preprocessor 0 to non-zero. This file's capitalized .F90 extension causes most Fortran compilers to preprocess this file so that building as follows enables assertion enforcement:
fpm build --flag "-DASSERTIONS"
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
logical, | private, | parameter | :: | enforce_assertions | = | .false. |
If assertion is .false., error-terminate with a character stop code that contains diagnostic_data if present
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in) | :: | assertion | Most assertions will be expressions such as i>0 |
||
character(len=*), | intent(in) | :: | description | A brief statement of what is being asserted such as "i>0" or "positive i" |
||
class(*), | intent(in), | optional | :: | diagnostic_data | Data to include in an error ouptput: may be of an intrinsic type or a type that extends characterizable_t |