Skip to content

COR100 misleading-inline-if-semicolon ​

warning enabled by default

A statement follows a one-line if after a semicolon: it is not conditional.

Why ​

In if (c) a = 1; b = 2 only a = 1 depends on the condition: the semicolon ends the if statement, and b = 2 always executes, although the line reads as if both were guarded. Use an if ... then ... end if block or put the second statement on its own line.

Reported ​

fortran
if (err /= 0) print *, 'failed'; stop

Preferred ​

fortran
if (err /= 0) then
  print *, 'failed'
  stop
end if

Suppressing ​

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

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

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

Equivalent ​

Fortitude rule C151 (see Lint Rules).