Skip to content

COR110 nonportable-shortcircuit-inquiry ​

warning enabled by default

A condition tests present/allocated/associated and uses the same entity in one expression.

Why ​

Fortran does not short-circuit .and./.or.: in present(x) .and. x > 0 the compiler may evaluate x > 0 even when x is absent, which is invalid and crashes with some compilers and options. Nest the tests (if (present(x)) then; if (x > 0) ...) or use a local copy set from the optional argument.

Reported ​

fortran
if (present(tol) .and. tol > 0) eps = tol

Preferred ​

fortran
if (present(tol)) then
  if (tol > 0) eps = tol
end if

Suppressing ​

For one occurrence, with the reason on the same line (or alone on the line before the statement):

fortran
! fobis: ignore[COR110] <why this occurrence is fine>

For the whole project, ignore = COR110 in the fobos [lint] section.

Equivalent ​

Fortitude rule C161 (see Lint Rules).