Fortran compiler standard enforce
Fortran compilers typically have options for enforcing Fortran standards.
The compilers raise additional warnings or errors for code that is not deemed compliant.
Fortran standard options can make false warnings, so we generally do not enable standards checking for user defaults.
However, we do enforce implicit none as a quality measure so that each variable must be declared.
It does not check if the variables are
assigned before use.
We recommend the Fortran 2018 statement:
implicit none (type, external)which requires explicitly defined procedure interfaces as well.
type- the traditional
implicit nonedefault external- introduced by Fortran 2018; requires explicit interface for external procedures.
| Compiler | Fortran standard flag | implicit none flag |
|---|---|---|
| GCC Gfortran | -std=f2018 | -fimplicit-none |
| LLVM Flang | -std=f2018 | -fimplicit-none |
AOCC aof |
-std=f2018 | -fimplicit-none |
Intel oneAPI ifx |
-stand:f18 | -warn:declarations |
NVIDIA HPC nvfortran |
-standard | -Mdclchk |
Cray ftn |
-n | -eI |
NAG Fortran nagfor |
-f2018 | -u |
CMake script to enforce implicit none:
if(CMAKE_Fortran_COMPILER_ID STREQUAL "Cray")
set(_fimpnone -eI)
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "GNU|LLVMFlang")
set(_fimpnone -fimplicit-none)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")
set(_fimpnone -warn:declarations)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC")
set(_fimpnone -Mdclchk)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "NAG")
set(_fimpnone -u)
endif()
set(_fimpnone "$<$<COMPILE_LANGUAGE:Fortran>:${_fimpnone}>")
target_compile_options(mytarg PRIVATE ${_fimpnone})