Risk of -fimplicit-none

Are there any risks of using the flag -fimplicit-none? I really cannot stand putting the implicit none in my code anymore.

I’d say you cannot write decent code without this option enabled. I always use it and add implicit none in my code, just in case someone else who works in the project decided to use the implicit typing. Double protection :wink:

1 Like

It is not clear what exactly “it” stands for. The compiler option that you have in the title, or the related IMPLICIT NONE statement in your source code? Or are you using some build system that takes compiler options from embedded directives in your source code? The possibilities for causing harm without becoming aware are quite numerous.

There are utilities that can add IMPLICIT NONE at appropriate places in source code (especially F77 or earlier code).

There are/have been a few compilers that have a rather risky nature. Based on the philosophy of supporting old complicated build scripts without requiring updating, those compilers may simply ignore compiler options, such as -fimplicit-none, that they do not currently support, but may have supported in the past.

1 Like

Intel compiler, for example, (sadly) does not have a similar implicit none compiler option. So as kargl said, your codebase will be bound to gfortran forever. I don’t know about the other compilers.

What I do is that I specify implicit none in all modules and submodule headers. But if you can forget it, you will forget to put it somewhere sometime. So, I also specify the compiler option whenever it is available. GFortran’s fantastic -fimplicit-none has helped to fix more than a few bugs so far in my experience.

@fortran4r , I assume your quoted comment implies you do not want to have to add the implicit none statement in your Fortran code, can you please confirm?

If so, please note you are not alone.

I’ve come across quite a few coders in teams in industry who have communicated the same want i.e., they do not want to have to introduce implicit none is every program unit, particularly INTERFACE blocks. Please see this thread: Eliminate implicit mapping

As to your question, please note the following: until and unless the standard makes implicit none the default and the compiler implementations conform to such true progress, it’s an incalculable risk to avoid it in your codes for actual work.

I, for one, avoid implicit none like the plague in any illustrative code I post online - I truly think it’s an abomination the state of Fortran circa 2021 requires it, but that’s just my view. Should I have to “code in anger” using Fortran, I would ensure implicit none is in effect explicitly in code in every program unit and INTERFACE body. It’s a shame, but that’s just how it is - take it or leave it, and many do leave.