Newer gfortran does not compile a Fortran90 code

I have a Fortran90 code that compiles and works great with gfortran 4.8.5. However, when I try to compile it with newer gfortran versions (I've tested from 6.3 to 11.2), it does not work!!

If I don't add any flags to gfortran-6.3+, I get Error: Blank required in STOP statement near (1).

If I add -std=f95, then I get Error: GNU Extension: Nonstandard type declaration or Error: Fortran 2003: Elemental function as initialization expression with non-integer/non-character arguments...

Any tips? Thanks!


  • The source


    is not a valid Fortran 90/95/2003/2008/2018 program.

    It is, however, a program that is accepted by GCC 4.8.5, seemingly with the intended result.

    It is accepted by this version of the compiler because it does not have the diagnostic capability to reject the program. Later versions of GCC do include such capability.

    No compiler is required to have this capability: the error in this source is one the programmer must take responsibility for. By using a newer compiler you are taking advantage of the improvements in its optional error checking focus. One should be grateful to a compiler which points out mistakes even when it doesn't have to.

    If you have broken code like my example here: fix it. Using the flag -std=f95 for later versions of GCC won't help: the flag requests checking for stricter conformance to the Fortran 95 standard (against allowing non-standard extensions or features from Fortran 2003+) but as above, the code is not valid Fortran 95 code.

    Note, however, that


    is a valid Fortran 90+ program in fixed-form source. If you're trying to compile fixed-form source as free-form source, then as above early versions of GCC will accept it while later versions will reject it. In this case, explicitly tell the compiler to compile as fixed-form source or change the source to be valid so-called intersection format.