This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [patch, fortran] fixes for functions
- From: Daniel Franke <franke dot daniel at gmail dot com>
- To: fortran at gcc dot gnu dot org
- Cc: burnus at net-b dot de, Brooks Moses <brooks dot moses at codesourcery dot com>
- Date: Thu, 12 Jul 2007 22:18:35 +0200
- Subject: Re: [patch, fortran] fixes for functions
- Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:from:to:subject:date:user-agent:references:in-reply-to:cc:mime-version:content-type:message-id; b=eGkONJryn9BdTLOTN2N4DmooBZw7gZwnM7AQ5Bb2UUJ/fm/pZk4XxOdTFWOOSQFDj9NXIXyBiM6IMWAKDM1O6Dc5U/XyFXmIaPpAilGNeJUr9WFuEbCcKzqWUdKbk3rPkZlc89m56sTVtzE7WYBKcLv882aV0PqS6hfdfnyWU8M=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:from:to:subject:date:user-agent:references:in-reply-to:cc:mime-version:content-type:message-id; b=Bi5KmH1Wy+u53VGAssRfCpAcCLPBHMDV7kjsJecsUxGVhzpTad395nzLy6cZCHZFaNovU9KNMnDwpWqwEIyykOwkuy40Wkycy3Wa4/Vj2QNRpPNwaorQjlGVyXdOUcAw1TqmvjPxmQr1INxiBcR9N0q7I/H3nsVguCSdiOhS20I=
- References: <1250.134.95.66.147.1184070503.squirrel@www.webmail.uni-koeln.de>
On Tuesday 10 July 2007 14:28:23 Tobias Burnus wrote:
> > 2007-07-09 Daniel Franke <franke.daniel@gmail.com>
> >
> > * decl.c (gfc_match_suffix): Removed surplus general error that hides
> > a more specific message.
> > * resolve.c (resolve_fl_variable): Reject illegal initializiers only
> > if not already done.
> > (resolve_fl_procedure): Added check for initializers of functions.
> >
> > Regression tested on i686-pc-linux-gnu. Ok for trunk?
>
> This patch fails for me when used with statement functions:
>
> Z2(x) = x*(Alft-x)/Vg - x*(x-Alfb)/Vf
> 1
> Error: Function 'z2' at (1) cannot have an inital value
>
> Actually, I also get tons of errors from the test suite for the same
> reason.
Tobias,
thanks again for catching this! The solution for statement functions turned
out to be straightforward.
I also changed the error message according to Brooks' suggestion. It now
reads: "cannot have an initializer" instead of "cannot have an initial
value".
gcc/fortran:
2007-07-09 Daniel Franke <franke.daniel@gmail.com>
PR fortran/31639
* decl.c (gfc_match_suffix): Removed surplus general error that hides
a more specific message.
* resolve.c (resolve_fl_variable): Reject illegal initializiers only
if not already done.
(resolve_fl_procedure): Added check for initializers of functions.
gcc/testsuite:
2007-07-09 Daniel Franke <franke.daniel@gmail.com>
PR fortran/31639
* gfortran.dg/func_decl_4.f90: New test.
Attached patch has been bootstrapped and regtested on i686-pc-linux-gnu.
Ok for trunk?
Daniel
Index: fortran/resolve.c
===================================================================
--- fortran/resolve.c (revision 126598)
+++ fortran/resolve.c (working copy)
@@ -6547,7 +6547,7 @@
}
/* Reject illegal initializers. */
- if (sym->value && flag)
+ if (!sym->mark && sym->value && flag)
{
if (sym->attr.allocatable)
gfc_error ("Allocatable '%s' at %L cannot have an initializer",
@@ -6745,6 +6745,14 @@
}
}
+ /* A function, that is not a statement-function, shall not have an initializer. */
+ if (sym->attr.function && sym->value && sym->attr.proc != PROC_ST_FUNCTION)
+ {
+ gfc_error ("Function '%s' at %L cannot have an initializer",
+ sym->name, &sym->declared_at);
+ return FAILURE;
+ }
+
/* An external symbol may not have an initializer because it is taken to be
a procedure. */
if (sym->attr.external && sym->value)
Index: fortran/decl.c
===================================================================
--- fortran/decl.c (revision 126598)
+++ fortran/decl.c (working copy)
@@ -3578,12 +3578,6 @@
break;
}
- if (is_result == MATCH_ERROR || is_bind_c == MATCH_ERROR)
- {
- gfc_error ("Error in function suffix at %C");
- return MATCH_ERROR;
- }
-
if (is_bind_c == MATCH_YES)
if (gfc_add_is_bind_c (&(sym->attr), sym->name, &gfc_current_locus, 1)
== FAILURE)
Index: testsuite/gfortran.dg/func_decl_4.f90
===================================================================
--- testsuite/gfortran.dg/func_decl_4.f90 (revision 0)
+++ testsuite/gfortran.dg/func_decl_4.f90 (revision 0)
@@ -0,0 +1,17 @@
+! { dg-do compile }
+! { dg-options "-c" }
+!
+! Functions shall not have an initializer.
+!
+
+function f1() ! { dg-error "cannot have an initializer" }
+ integer :: f1 = 42
+end function
+
+function f2() RESULT (r) ! { dg-error "cannot have an initializer" }
+ integer :: r = 42
+end function
+
+function f3() RESULT (f3) ! { dg-error "must be different than function name" }
+ integer :: f3 = 42
+end function ! { dg-excess-errors "" }