[Bug fortran/88079] warn about procedure arguments without INTENT

2019-07-01 Thread mark.eggleston at codethink dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88079

--- Comment #6 from MarkEggleston  ---
Where a module is used:

module foo
  implicit none

  interface
subroutine dusty(n)
  integer :: n
end subroutine
  end interface

contains
  subroutine bar(n)
integer, intent(in) :: n
real :: x
print *,"bar before dusty", n
call dusty(n)
print *,"bar after dusty", n
  end subroutine bar

end module foo

subroutine dusty(n)
  integer :: n
  n = n - 1
end

program main
  use foo
  implicit none
  integer :: n
  n = 5
  call bar(n)

end program main

The call to dusty in bar would be with an implicit interface were it not for
the interface block. I get the same warnings as in comment 5.

I would like to also issue a warning for the interface block but don't I know
where I could insert an code to issue a warning anywhere near the interface
block. I know where the dummy variable is processed from a lexical point of
view but I don't know where the interface block is handled. Some indication of
where to look would be greatly appreciated.

[Bug fortran/88079] warn about procedure arguments without INTENT

2019-07-01 Thread mark.eggleston at codethink dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88079

--- Comment #5 from MarkEggleston  ---
Given the program below:

program main
  implicit none
  integer :: n
  n = 5
  call bar(n)

end program main

subroutine bar(n)
  integer, intent(in) :: n
  real :: x
  print *,"bar before dusty", n
  call dusty(n)
  print *,"bar after dusty", n
end subroutine bar

subroutine dusty(n)
  integer :: n
  n = n - 1
end

the attached patch produces the following warnings:

pr88079_2.f90:19:2:

   19 |   n = n - 1
  |  1
Warning: Dummy variable 'n' in assignment at (1) has missing INTENT or VALUE
[-Wintent]
pr88079_2.f90:13:15:

   13 |   call dusty(n)
  |   1
Warning: Dummy variable 'n' at (1) has INTENT(IN) and may be modified
[-Wintent]
pr88079_2.f90:17:18:

   17 | subroutine dusty(n)
  |  1
Warning: Dummy variable 'n' in assignment at (1) has missing INTENT or VALUE
[-Wintent]

Note: if compiles with a standard earlier than Fortran 2003 "or VALUE" will be
omitted.

I'm not happy with the location of the last warning which is why it is worded
as it is. I would prefer the following:

   18 |   integer :: n
  |   1
Warning: Missing INTENT or VALUE at (1)

I currently don't know enough about identifying the location of a warning or
error to determine whether this can be done.

Where dusty(n) is called the interface to dusty is known, however, this is not
always the case so the attribute of the associate dummy variable can always be
checked. To help identify a potential problem -Wimplicit-inteface can be used.

[Bug fortran/88079] warn about procedure arguments without INTENT

2019-07-01 Thread mark.eggleston at codethink dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88079

--- Comment #4 from MarkEggleston  ---
Created attachment 46539
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46539=edit
Warn about missing intent or value

Work in progress. Warns at declaration, assignment and possible modification of
a procedure argument.

[Bug fortran/88079] warn about procedure arguments without INTENT

2019-06-27 Thread mark.eggleston at codethink dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88079

MarkEggleston  changed:

   What|Removed |Added

 CC||mark.eggleston at codethink 
dot co
   ||m

--- Comment #3 from MarkEggleston  ---
I propose that -Wintent be added that would provide warnings in the following
circumstances:

1. At declaration of a dummy variable, this will include interface blocks.
2. Assignment of a value to a dummy variable that has no intent specified
(unless it has the value attribute (Fortran 2003)).
3. When dummy variable (with unknown or in intent) is used as an argument to a
procedure where the intent of the associated dummy variable is unknown, out or
inout. This would also apply where an implicit interface is used.

The reason a warning should be issued at declaration is so that a suitable
warning is raised when there is no way of determining whether the variable can
be changed as the procedure is only known by its interface i.e. it is compiled
separately.

Code that does not specify the intent of dummy values run the risk containing
errors that will result in the program crashing at runtime, e.g. calling a
procedure with a constant as an argument and the associated dummy variable is
modified. Catching potential bugs at compile time is preferable.

Using -Wintent in conjunction with -Wimplicit-interface and -Werror will
encourage the use of interface blocks and intent thus improving Fortran code.

[Bug fortran/88079] warn about procedure arguments without INTENT

2019-01-15 Thread tkoenig at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88079

Thomas Koenig  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2019-01-15
 CC||tkoenig at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #2 from Thomas Koenig  ---
(In reply to kargl from comment #1)

> How does gfortran differential between new Fortran code and
> old Fortran code.  It is the programmer's responsibility to 
> know what he or she is doing.

Well, anybody who wants to use old code should never use
such an option :-)

This could be useful, I suppose.

[Bug fortran/88079] warn about procedure arguments without INTENT

2018-11-30 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88079

kargl at gcc dot gnu.org changed:

   What|Removed |Added

   Priority|P3  |P5
   Severity|normal  |enhancement

--- Comment #1 from kargl at gcc dot gnu.org ---
(In reply to Vivek Rao from comment #0)
> I think all new Fortran code should have the INTENT specified for the
> arguments of all procedures. I request that gfortran add a warning for code
> not doing this. If a warning is added, users who agree with my style
> recommendation can use a -Werror flag to force them to fix code without
> INTENTs for all arguments.
> 
> This is, of course, an enhancement request, not a bug report.

How does gfortran differential between new Fortran code and
old Fortran code.  It is the programmer's responsibility to 
know what he or she is doing.