Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

suggestion for a new warning

Alexis_R_
New Contributor I
554 Views

Call me lazy, but I love to rely on the compiler's warnings to help me write better code faster. One mistake I make occasionally is forgetting to check whether an optional dummy argument was present. I would really like ifort to tell me when any dummy argument's presence hasn't been checked within the procedure.

E.g. compiling this with -warn all should give a warning about "norm"...

[fortran]module testmod1
	contains
	real function fn(a,b,norm)
		implicit none
		real, intent(in) :: a
		real, intent(in) :: b
		real, optional, intent(in) :: norm
		!
		fn = a/norm + b
	end function fn
end module

program test
	use testmod1
	print *, fn(1.2,3.14,200.1)
end program[/fortran]

Is there some reason why this warning does not exist?

I hope this forum is an appropriate place to make suggestions like this.

0 Kudos
4 Replies
Steven_L_Intel1
Employee
554 Views
The compiler really has no way of knowing this at compile time. You could use some other means than PRESENT to test for the argument. It would require some sort of code flow analysis and could be fooled if you passed the optional argument to another routine. You will very likely get a segfault at run-time if you access an omitted argument.
0 Kudos
Alexis_R_
New Contributor I
554 Views
The compiler really has no way of knowing this at compile time. You could use some other means than PRESENT to test for the argument. It would require some sort of code flow analysis and could be fooled if you passed the optional argument to another routine. You will very likely get a segfault at run-time if you access an omitted argument.

I see... Thanks for your answer.

Seems to me that if a procedure has an optional dummy foo and there is no present(foo) anywhere in the procedure, that would be a good enough reason to issue a warning, or at least an info.

I can't remember whether it was ifort or gfortran, but I'm pretty sure I've seen warnings from a -check uninit-like option (~ "this variable is used but may be uninitialized") which were sometimes wrong (perhaps because their rules were too simple), but they are still very useful..

In other words, isn't an info or warning message, if phrase appropriately ("may", "appears to be"), allowed to be wrong?

Doesn't your argument above apply equally to -check uninit?

0 Kudos
Steven_L_Intel1
Employee
554 Views

We could add a run-time check which is what -check uninit does. But as I mentioned you're going to get an error anyway - a segfault. As I mentioned earlier, PRESENT is not the only way you can avoid referencing an omitted argument.

I will add a feature request on your behalf.

0 Kudos
Alexis_R_
New Contributor I
554 Views
Thanks Steve, this was clearly a half-baked idea, but maybe there's a useful feature in there somewhere :)
0 Kudos
Reply