Commit ca071303 by Francois-Xavier Coudert Committed by Daniel Kraft

re PR fortran/22552 (Would like warning when an undeclared function is called)

2009-12-27  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
	    Daniel Kraft  <d@domob.eu>

	PR fortran/22552
	* lang.opt (Wimplicit-procedure): New option.
	* gfortran.h (struct gfc_option_t): New member `warn_implicit_procedure'
	* options.c (gfc_handle_option): Handle -Wimplicit-procedure.
	* interface.c (gfc_procedure_use): Warn about procedure never
	explicitly declared if requested by the new flag.
	* invoke.texi: Document new flag -Wimplicit-procedure.

2009-12-27  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
	    Daniel Kraft  <d@domob.eu>

	PR fortran/22552
	* gfortran.dg/warn_implicit_procedure_1.f90: New test.

Co-Authored-By: Daniel Kraft <d@domob.eu>

From-SVN: r155479
parent 6f352c3a
2009-12-27 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Daniel Kraft <d@domob.eu>
PR fortran/22552
* lang.opt (Wimplicit-procedure): New option.
* gfortran.h (struct gfc_option_t): New member `warn_implicit_procedure'
* options.c (gfc_handle_option): Handle -Wimplicit-procedure.
* interface.c (gfc_procedure_use): Warn about procedure never
explicitly declared if requested by the new flag.
* invoke.texi: Document new flag -Wimplicit-procedure.
2009-12-17 Janus Weil <janus@gcc.gnu.org> 2009-12-17 Janus Weil <janus@gcc.gnu.org>
PR fortran/42144 PR fortran/42144
......
...@@ -2103,6 +2103,7 @@ typedef struct ...@@ -2103,6 +2103,7 @@ typedef struct
int warn_ampersand; int warn_ampersand;
int warn_conversion; int warn_conversion;
int warn_implicit_interface; int warn_implicit_interface;
int warn_implicit_procedure;
int warn_line_truncation; int warn_line_truncation;
int warn_surprising; int warn_surprising;
int warn_tabs; int warn_tabs;
......
...@@ -2380,12 +2380,18 @@ gfc_procedure_use (gfc_symbol *sym, gfc_actual_arglist **ap, locus *where) ...@@ -2380,12 +2380,18 @@ gfc_procedure_use (gfc_symbol *sym, gfc_actual_arglist **ap, locus *where)
/* Warn about calls with an implicit interface. Special case /* Warn about calls with an implicit interface. Special case
for calling a ISO_C_BINDING becase c_loc and c_funloc for calling a ISO_C_BINDING becase c_loc and c_funloc
are pseudo-unknown. */ are pseudo-unknown. Additionally, warn about procedures not
if (gfc_option.warn_implicit_interface explicitly declared at all if requested. */
&& sym->attr.if_source == IFSRC_UNKNOWN if (sym->attr.if_source == IFSRC_UNKNOWN && ! sym->attr.is_iso_c)
&& ! sym->attr.is_iso_c) {
gfc_warning ("Procedure '%s' called with an implicit interface at %L", if (gfc_option.warn_implicit_interface)
sym->name, where); gfc_warning ("Procedure '%s' called with an implicit interface at %L",
sym->name, where);
else if (gfc_option.warn_implicit_procedure
&& sym->attr.proc == PROC_UNKNOWN)
gfc_warning ("Procedure '%s' called at %L is not explicitly declared",
sym->name, where);
}
if (sym->attr.if_source == IFSRC_UNKNOWN) if (sym->attr.if_source == IFSRC_UNKNOWN)
{ {
......
...@@ -137,9 +137,9 @@ and warnings}. ...@@ -137,9 +137,9 @@ and warnings}.
@gccoptlist{-fmax-errors=@var{n} @gol @gccoptlist{-fmax-errors=@var{n} @gol
-fsyntax-only -pedantic -pedantic-errors @gol -fsyntax-only -pedantic -pedantic-errors @gol
-Wall -Waliasing -Wampersand -Warray-bounds -Wcharacter-truncation @gol -Wall -Waliasing -Wampersand -Warray-bounds -Wcharacter-truncation @gol
-Wconversion -Wimplicit-interface -Wline-truncation -Wintrinsics-std @gol -Wconversion -Wimplicit-interface -Wimplicit-procedure -Wline-truncation @gol
-Wsurprising -Wno-tabs -Wunderflow -Wunused-parameter -Wintrinsics-shadow @gol -Wintrinsics-std -Wsurprising -Wno-tabs -Wunderflow -Wunused-parameter @gol
-Wno-align-commons} -Wintrinsics-shadow -Wno-align-commons}
@item Debugging Options @item Debugging Options
@xref{Debugging Options,,Options for debugging your program or GNU Fortran}. @xref{Debugging Options,,Options for debugging your program or GNU Fortran}.
...@@ -754,6 +754,12 @@ Warn if a procedure is called without an explicit interface. ...@@ -754,6 +754,12 @@ Warn if a procedure is called without an explicit interface.
Note this only checks that an explicit interface is present. It does not Note this only checks that an explicit interface is present. It does not
check that the declared interfaces are consistent across program units. check that the declared interfaces are consistent across program units.
@item -Wimplicit-procedure
@opindex @code{Wimplicit-procedure}
@cindex warnings, implicit procedure
Warn if a procedure is called that has neither an explicit interface
nor has been declared as @code{EXTERNAL}.
@item -Wintrinsics-std @item -Wintrinsics-std
@opindex @code{Wintrinsics-std} @opindex @code{Wintrinsics-std}
@cindex warnings, non-standard intrinsics @cindex warnings, non-standard intrinsics
......
...@@ -96,6 +96,10 @@ Wimplicit-interface ...@@ -96,6 +96,10 @@ Wimplicit-interface
Fortran Warning Fortran Warning
Warn about calls with implicit interface Warn about calls with implicit interface
Wimplicit-procedure
Fortran Warning
Warn about called procedures not explicitly declared
Wline-truncation Wline-truncation
Fortran Warning Fortran Warning
Warn about truncated source lines Warn about truncated source lines
......
...@@ -561,6 +561,10 @@ gfc_handle_option (size_t scode, const char *arg, int value) ...@@ -561,6 +561,10 @@ gfc_handle_option (size_t scode, const char *arg, int value)
gfc_option.warn_implicit_interface = value; gfc_option.warn_implicit_interface = value;
break; break;
case OPT_Wimplicit_procedure:
gfc_option.warn_implicit_procedure = value;
break;
case OPT_Wline_truncation: case OPT_Wline_truncation:
gfc_option.warn_line_truncation = value; gfc_option.warn_line_truncation = value;
break; break;
......
2009-12-27 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Daniel Kraft <d@domob.eu>
PR fortran/22552
* gfortran.dg/warn_implicit_procedure_1.f90: New test.
2009-12-24 Jason Merrill <jason@redhat.com> 2009-12-24 Jason Merrill <jason@redhat.com>
PR c++/41305 PR c++/41305
......
! { dg-do compile }
! { dg-options "-Wimplicit-procedure" }
! PR fortran/22552
! Check for correct -Wimplicit-procedure warnings.
MODULE m
CONTAINS
SUBROUTINE my_sub ()
END SUBROUTINE my_sub
INTEGER FUNCTION my_func ()
my_func = 42
END FUNCTION my_func
END MODULE m
SUBROUTINE test (proc)
IMPLICIT NONE
CALL proc () ! { dg-bogus "is not explicitly declared" }
END SUBROUTINE test
PROGRAM main
USE m
EXTERNAL :: ext_sub
EXTERNAL :: test
INTEGER :: ext_func
CALL ext_sub () ! { dg-bogus "is not explicitly declared" }
PRINT *, ext_func () ! { dg-bogus "is not explicitly declared" }
PRINT *, implicit_func () ! { dg-bogus "is not explicitly declared" }
CALL my_sub () ! { dg-bogus "is not explicitly declared" }
PRINT *, my_func () ! { dg-bogus "is not explicitly declared" }
PRINT *, SIN (3.14159) ! { dg-bogus "is not explicitly declared" }
CALL undef_sub (1, 2, 3) ! { dg-warning "is not explicitly declared" }
! Can't check undefined function, because it needs to be declared a type
! in any case (and the implicit type is enough to not trigger this warning).
END PROGRAM
! { dg-final { cleanup-modules "m" } }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment