Skip to content

COR070 missing-default-case ​

warning enabled by default

A select case construct has no case default.

Why ​

When no case matches, a select case without case default does nothing, silently. A value that was not foreseen (a new option, a corrupted input) then flows on unhandled. Add case default, even if only to stop with an error that names the unexpected value.

Reported ​

fortran
select case (scheme)
case ('weno5')
  call weno5(q)
case ('weno7')
  call weno7(q)
end select

Preferred ​

fortran
select case (scheme)
case ('weno5')
  call weno5(q)
case ('weno7')
  call weno7(q)
case default
  error stop 'unknown scheme: '//scheme
end select

Suppressing ​

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

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

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

Equivalent ​

Fortitude rule C011 (see Lint Rules).