Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

enforce implicit none

ggveldkamp2
Novice
1,485 Views
I was wondering if there is a method of enforcing "implicit none" with some compiler option. I am already using /warn:declarations but I would like the compiler to stop with an error when an undeclared variable is encounterd.
Is there a compiler option to turn certain warnings into errors?

Guido

13 Replies
Steven_L_Intel1
Employee
1,485 Views
There is not at present an option to turn only selected warnings into errors. /warn:errors will turn ALL warnings into errors. However, the diagnostic you get with /warn:declarations is in fact an error severity and the behavior is the same as if you had said IMPLICIT NONE.
0 Kudos
grg99
Beginner
1,485 Views
I think if you declare the routines in a module, and put "IMPLICIT NONE" at the head of the module, all the subroutines and function inherit the implicitaneousness. So that's one near-miss of a way of doing it. If I'm correct.


0 Kudos
jimdempseyatthecove
Honored Contributor III
1,485 Views

In IVF 10.nn you have

/4{Y|N}d enable/disable default IMPLICIT NONE

Jim Dempsey

0 Kudos
Steven_L_Intel1
Employee
1,485 Views
That's simply the Microsoft Fortran PowerStation spelling of /warn:declarations. It does the same thing.
0 Kudos
ggveldkamp2
Novice
1,485 Views
Hello Steve,
Do you know if an option to turn certain warnings into error is considered for a future version of the compiler?

Regards,
Guido

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,485 Views

Guido,

As an interum measure you could write a script to scan the BuildLog for the warning messages and make it a post build process and/or Tool.

You could get fancy and make the application multiple projects, one being an empty main that calls the old main (program). Then make a verification project that scans the build log files and which builds a bogus subroutine.Structure it soverificatioin project will fail to build the bogus subroutine (deleting the old copy in the failure) and then the main will fail to link.

Jim Dempsey

0 Kudos
Steven_L_Intel1
Employee
1,485 Views
I know we plan to offer finer-grained control over diagnostics. I don't recall if changing severity of specific diagnostics is part of the plan.
0 Kudos
ggveldkamp2
Novice
1,485 Views
Hello Jim,

We have a lot of (legacy) source code in many files for several programs. We use make as a build system. I have written a small tool to scan the source files and list all the functions and subroutines that don't have "implicit none". I have added "implicit none" to all our source now and I hoped I could prevent people from forgetting to add "implicit none" to new functions.
In my opinion implicit typing might be a good thing for the lazy programmer but if you are not very careful it will lead to bugs.
I also plan on using the /gen-interfaces option in the future to prevent even more bugs :-)

Regards,

Guido

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,485 Views

Guido,

I too have been bitten by implicit many times over my 35 years of programming. Often it is due to a typographical error or ommission of inclusion of a header file or mod file.

I use TECO for making such global editing tasks.

Jim Dempsey

0 Kudos
Steven_L_Intel1
Employee
1,485 Views
Guido,

If you want to enforce IMPLICIT NONE for all compiles on your system, edit the file ifort.cfg, found in the compiler's BIN folder, and add:

/warn:declarations

If you just save the file in place, it will be used until you update the compiler. You can save a copy elsewhere and define the system environment variable IFORTCFG to have a value of the complete path to the configuration file.
0 Kudos
ggveldkamp2
Novice
1,485 Views
Hello Steve,

I already use /warn:declarations (from the makefile), the only thing is that it generates a warning and not an error (ivf 9.1).

Regards,

Guido

0 Kudos
Steven_L_Intel1
Employee
1,485 Views
I see you are correct - I thought it was an error but it is indeed a warning. You could also add /warn:error which will change all warnings to errors.
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,485 Views

Guido,

As a work around, add the compiler option /Qdiag-file:YourNameHere.diag

Then in your make file

grep explicit.type Debug*.diag>NoType.txt

This assumes you have GREP.

If NoType.txt is 0 bytes in size then no error. Using one ofthe script languages (AWK, PEARL, other, or roll your own) you can make a test of NoType.txt and if not 0 length your make file can delete the execuitable or perform other such action as you see fit (delete offending .obj file prior to link).

Jim

0 Kudos
Reply