Disable warnings on a per-file basis?

While using the Modern Fortran extension, is it possible to disable warnings such as “Wunused-variable” via some comment at the top of the file?

If you are using a build tool like make(1) you can give different rules to different files; but there is not a standard method for reading options from the files themselves.

People do make their own aliases for the compiler command that look for such options; look up options in sqlite3 data files and so on but I know of no standardized method to do what you ask.

I would not recommend it myself, but the most common method is using the cpp/fpp preprocessor and then calling the compiler from the bash shell with something like this syntax

gfortran $(cpp -P -DGFORTRAN -DDEBUG xx.F90) xx.F90
gfortran $(cpp -P -DGFORTRAN  xx.F90) xx.F90
ifort $(cpp -P -DIFORT    -DDEBUG xx.F90) xx.F90
ifort $(cpp -P -DIFORT     xx.F90) xx.F90
#ifdef DEBUG
 -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single
 -O3 -funroll-loops -Wimplicit-interface -fPIC -fmax-errors=1 -fcoarray=single
#elif IFORT
#ifdef DEBUG
 -warn all -check all -error-limit 1 -O0 -g -assume byterecl -traceback
 -fp-model precise -pc64 -align all -error-limit 1 -reentrancy threaded -nogen-interfaces -assume byterecl
program demo_clip
implicit none
integer :: ii(2,3), i
data ii/10,20,30,40,50,60/
end program demo_clip

but using something like Makefiles is much much more common.

1 Like

Short answer is no, since the linter options are defined globally (on a oer project basis).

Long answer, there are probably ways to “hack” vscode and gfortran by passing environmental settings but I would not recommend it.

The long term plan to address this is to integrate with fpm and cmake serving lint diagnostics based on the build system options.