There are lots of compiler options in various compilers, and also newer options are constantly added to more recent versions. So I would appreciate it if you share the information about options that you find useful in your actual coding
In my case, I found -finit-derived in gfortran useful, which initializes components of derived types with some specified values (e.g., NaN for reals). For example, for this code
program main
implicit none
type Foo
integer :: n
real :: x
complex :: z
character(5) :: s
endtype
type(Foo) :: f
print *, f
end
The -finit-derived is a good one and should be used also, I didn’t know about it. The -ffpe-trap are important to stop a program when a NaN is generated, and the -fbacktrace is important to give you a nice stacktrace.
Gfortran is my main compiler and is excellent, but g95 is my sentimental favorite and has good compile-time checks. It does not support much of Fortran 2003 and beyond.
The result of compiling the code above with the options I use, g95 -c -Wall -Wextra -Wimplicit-none -Werror=100,113,115,137,146,147,159,163 -ftrace=full -fbounds-check -freal=nan -fmodule-private -Wno=112,167 is
In file xxmain.f90:9
type(Foo) :: f
1
Error (113): Variable ‘f’ at (1) is used but not set
I have started a new subproject in my Flibs project at http://flibs.sourceforge.net to examine the capabilities of compilers (and perhaps more dedicated tools) to identify via static analysis problems in the source code. It is something I have been thinking about for some time and with a discussion at work about static analysis of source code in mind I simply sat down for it. Far from complete, but at least there are a few test programs now :).
Main issue: get some framework up and running (like for chkfeatures) but one that reports a nice summary.
Thanks for doing this. The compilers I see discussed are MicroSoft FORTRAN version 5.1 and Lahey. Presumably more modern compilers will be added. You comment favorably on Lahey, and I can confirm that Lahey/Fujitsu Fortran 95 was very good at flagging dubious code. There is an online Fortran Source Check.
Could you mirror your work at GitHub, which I think is the most popular code repository? I do see an flibs fork.
Up to now I have been too lazy (or awed?) to actually do that, but I am gaining more experience with Github and, frankly, SourceForge is evermore uncomfortable to work with.