diff mbox

[Fortran] PR 47550 - add "Fortran 2008" -std= diagnostic for PURE + VALUE

Message ID 4D51BF97.8080608@net-b.de
State New
Headers show

Commit Message

Tobias Burnus Feb. 8, 2011, 10:11 p.m. UTC
Instead of just swallowing dummies with VALUE and w/o INTENT in PURE 
procedures, reject it for -std=f95/f2003.

Build and regtested on x86-64-linux

Tobias

PS:

Comments

Tobias Burnus Feb. 11, 2011, 8:36 p.m. UTC | #1
0.5 * ping

On 8 February 2011,Tobias Burnus wrote:
> Instead of just swallowing dummies with VALUE and w/o INTENT in PURE 
> procedures, reject it for -std=f95/f2003.
>
> Build and regtested on x86-64-linux
>
> Tobias
>
> PS:
> pure-value-2.diff
>
>
> 2011-02-01  Tobias Burnus<burnus@net-b.de>
>
> 	PR fortran/47550
> 	* resolve.c (resolve_formal_arglist): PURE with VALUE
> 	and no INTENT: Add -std= diagnostics.
>
> 2011-02-01  Tobias Burnus<burnus@net-b.de>
>
> 	PR fortran/47550
> 	* gfortran.dg/pure_formal_2.f90: New.
>
> diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
> index 2a0fc49..25a3ad2 100644
> --- a/gcc/fortran/resolve.c
> +++ b/gcc/fortran/resolve.c
> @@ -338,17 +338,31 @@ resolve_formal_arglist (gfc_symbol *proc)
>         if (gfc_pure (proc)&&  !sym->attr.pointer
>   	&&  sym->attr.flavor != FL_PROCEDURE)
>   	{
> -	  if (proc->attr.function&&  sym->attr.intent != INTENT_IN
> -	&&  !sym->attr.value)
> -	    gfc_error ("Argument '%s' of pure function '%s' at %L must be "
> -		       "INTENT(IN) or VALUE", sym->name, proc->name,
> -		&sym->declared_at);
> +	  if (proc->attr.function&&  sym->attr.intent != INTENT_IN)
> +	    {
> +	      if (sym->attr.value)
> +		gfc_notify_std (GFC_STD_F2008, "Fortran 2008: Argument '%s' "
> +				"of pure function '%s' at %L with VALUE "
> +				"attribute but without INTENT(IN)", sym->name,
> +				proc->name,&sym->declared_at);
> +	      else
> +		gfc_error ("Argument '%s' of pure function '%s' at %L must be "
> +			   "INTENT(IN) or VALUE", sym->name, proc->name,
> +			&sym->declared_at);
> +	    }
>
> -	  if (proc->attr.subroutine&&  sym->attr.intent == INTENT_UNKNOWN
> -	&&  !sym->attr.value)
> -	    gfc_error ("Argument '%s' of pure subroutine '%s' at %L must "
> +	  if (proc->attr.subroutine&&  sym->attr.intent == INTENT_UNKNOWN)
> +	    {
> +	      if (sym->attr.value)
> +		gfc_notify_std (GFC_STD_F2008, "Fortran 2008: Argument '%s' "
> +				"of pure subroutine '%s' at %L with VALUE "
> +				"attribute but without INTENT", sym->name,
> +				proc->name,&sym->declared_at);
> +	      else
> +		gfc_error ("Argument '%s' of pure subroutine '%s' at %L must "
>   		       "have its INTENT specified or have the VALUE "
>   		       "attribute", sym->name, proc->name,&sym->declared_at);
> +	    }
>   	}
>
>         if (proc->attr.implicit_pure&&  !sym->attr.pointer
> --- /dev/null	2011-02-01 07:33:44.195999996 +0100
> +++ gcc/gcc/testsuite/gfortran.dg/pure_formal_2.f90	2011-02-01 15:05:21.000000000 +0100
> @@ -0,0 +1,18 @@
> +! { dg-do compile }
> +! { dg-options "-std=f2003" }
> +!
> +! PR fortran/47550
> +! Follow up to: PR fortran/47507
> +!
> +! PURE procedures: Allow arguments w/o INTENT if they are VALUE
> +!
> +
> +pure function f(x) ! { dg-error "Fortran 2008: Argument 'x' of pure function" }
> +  real, VALUE :: x
> +  real :: f
> +  f = sin(x)
> +end function f
> +
> +pure subroutine sub(x) ! { dg-error "Fortran 2008: Argument 'x' of pure subroutine" }
> +  real, VALUE :: x
> +end subroutine sub
Steve Kargl Feb. 11, 2011, 8:50 p.m. UTC | #2
On Fri, Feb 11, 2011 at 09:36:34PM +0100, Tobias Burnus wrote:
> 0.5 * ping

Whoops. I thought you had committed this.  See 
some style issues below.  OK to commit after
addressing comments.

> On 8 February 2011,Tobias Burnus wrote:
> >Instead of just swallowing dummies with VALUE and w/o INTENT in PURE 
> >procedures, reject it for -std=f95/f2003.
> >
> >Build and regtested on x86-64-linux
> >
> >Tobias
> >
> >PS:
> >pure-value-2.diff
> >
> >
> >2011-02-01  Tobias Burnus<burnus@net-b.de>
> >
> >	PR fortran/47550
> >	* resolve.c (resolve_formal_arglist): PURE with VALUE
> >	and no INTENT: Add -std= diagnostics.
> >
> >2011-02-01  Tobias Burnus<burnus@net-b.de>
> >
> >	PR fortran/47550
> >	* gfortran.dg/pure_formal_2.f90: New.
> >
> >diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
> >index 2a0fc49..25a3ad2 100644
> >--- a/gcc/fortran/resolve.c
> >+++ b/gcc/fortran/resolve.c
> >@@ -338,17 +338,31 @@ resolve_formal_arglist (gfc_symbol *proc)
> >        if (gfc_pure (proc)&&  !sym->attr.pointer

Space before &&

> >  	&&  sym->attr.flavor != FL_PROCEDURE)
> >  	{
> >-	  if (proc->attr.function&&  sym->attr.intent != INTENT_IN
> >-	&&  !sym->attr.value)
> >-	    gfc_error ("Argument '%s' of pure function '%s' at %L must be "
> >-		       "INTENT(IN) or VALUE", sym->name, proc->name,
> >-		&sym->declared_at);
> >+	  if (proc->attr.function&&  sym->attr.intent != INTENT_IN)

Likewise.

> >+	    {
> >+	      if (sym->attr.value)
> >+		gfc_notify_std (GFC_STD_F2008, "Fortran 2008: Argument '%s' "
> >+				"of pure function '%s' at %L with VALUE "
> >+				"attribute but without INTENT(IN)", 

See below.

> >sym->name,
> >+				proc->name,&sym->declared_at);
> >+	      else
> >+		gfc_error ("Argument '%s' of pure function '%s' at %L must 
> >be "
> >+			   "INTENT(IN) or VALUE", sym->name, proc->name,
> >+			&sym->declared_at);
> >+	    }
> >
> >-	  if (proc->attr.subroutine&&  sym->attr.intent == INTENT_UNKNOWN
> >-	&&  !sym->attr.value)
> >-	    gfc_error ("Argument '%s' of pure subroutine '%s' at %L must "
> >+	  if (proc->attr.subroutine&&  sym->attr.intent == INTENT_UNKNOWN)

Space before &&.

> >+	    {
> >+	      if (sym->attr.value)
> >+		gfc_notify_std (GFC_STD_F2008, "Fortran 2008: Argument '%s' "
> >+				"of pure subroutine '%s' at %L with VALUE "
> >+				"attribute but without INTENT", sym->name,

INTENT(IN)?  See above message.  Are the intent requirements
different for functions and subroutines?

> >+				proc->name,&sym->declared_at);
> >+	      else
> >+		gfc_error ("Argument '%s' of pure subroutine '%s' at %L must 
> >"
> >  		       "have its INTENT specified or have the VALUE "
> >  		       "attribute", sym->name, proc->name,&sym->declared_at);
> >+	    }
> >  	}
> >
> >        if (proc->attr.implicit_pure&&  !sym->attr.pointer
> >--- /dev/null	2011-02-01 07:33:44.195999996 +0100
> >+++ gcc/gcc/testsuite/gfortran.dg/pure_formal_2.f90	2011-02-01 
> >15:05:21.000000000 +0100
> >@@ -0,0 +1,18 @@
> >+! { dg-do compile }
> >+! { dg-options "-std=f2003" }
> >+!
> >+! PR fortran/47550
> >+! Follow up to: PR fortran/47507
> >+!
> >+! PURE procedures: Allow arguments w/o INTENT if they are VALUE
> >+!
> >+
> >+pure function f(x) ! { dg-error "Fortran 2008: Argument 'x' of pure 
> >function" }
> >+  real, VALUE :: x
> >+  real :: f
> >+  f = sin(x)
> >+end function f
> >+
> >+pure subroutine sub(x) ! { dg-error "Fortran 2008: Argument 'x' of pure 
> >subroutine" }
> >+  real, VALUE :: x
> >+end subroutine sub
Tobias Burnus Feb. 11, 2011, 9:12 p.m. UTC | #3
Steve Kargl wrote:
> Whoops. I thought you had committed this. See some style issues below. 
> OK to commit after addressing comments.

Thanks for the review.

Regarding the spacing issue: That seems to be a quoting bug in 
Thunderbird. The local version of patch and the original email seem to 
be OK: http://gcc.gnu.org/ml/fortran/2011-02/msg00059.html

Regarding:

>>> +		gfc_notify_std (GFC_STD_F2008, "Fortran 2008: Argument '%s' "
>>> +				"of pure subroutine '%s' at %L with VALUE "
>>> +				"attribute but without INTENT", sym->name,
> INTENT(IN)?  See above message.  Are the intent requirements
> different for functions and subroutines?

Yes, the idea seems to be that a PURE function does not affect its 
arguments while such a requirement does not make sense for subroutines. 
Thus the standard has:

C1276 The specification-part of a pure function subprogram shall specify 
that all its nonpointer dummy data objects have the INTENT (IN) or the 
VALUE attribute.
C1277 The specification-part of a pure subroutine subprogram shall 
specify the intents of all its nonpointer dummy data objects that do not 
have the VALUE attribute.

Committed as Rev. 170060.

Tobias
Steve Kargl Feb. 11, 2011, 9:39 p.m. UTC | #4
On Fri, Feb 11, 2011 at 10:12:45PM +0100, Tobias Burnus wrote:
> >>>+		gfc_notify_std (GFC_STD_F2008, "Fortran 2008: Argument '%s' "
> >>>+				"of pure subroutine '%s' at %L with VALUE "
> >>>+				"attribute but without INTENT", sym->name,
> >INTENT(IN)?  See above message.  Are the intent requirements
> >different for functions and subroutines?
> 
> Yes, the idea seems to be that a PURE function does not affect its 
> arguments while such a requirement does not make sense for subroutines. 
> Thus the standard has:
> 
> C1276 The specification-part of a pure function subprogram shall specify 
> that all its nonpointer dummy data objects have the INTENT (IN) or the 
> VALUE attribute.
> C1277 The specification-part of a pure subroutine subprogram shall 
> specify the intents of all its nonpointer dummy data objects that do not 
> have the VALUE attribute.

Thanks for the explanation.
diff mbox

Patch

2011-02-01  Tobias Burnus  <burnus@net-b.de>

	PR fortran/47550
	* resolve.c (resolve_formal_arglist): PURE with VALUE
	and no INTENT: Add -std= diagnostics.

2011-02-01  Tobias Burnus  <burnus@net-b.de>

	PR fortran/47550
	* gfortran.dg/pure_formal_2.f90: New.

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 2a0fc49..25a3ad2 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -338,17 +338,31 @@  resolve_formal_arglist (gfc_symbol *proc)
       if (gfc_pure (proc) && !sym->attr.pointer
 	  && sym->attr.flavor != FL_PROCEDURE)
 	{
-	  if (proc->attr.function && sym->attr.intent != INTENT_IN
-	      && !sym->attr.value)
-	    gfc_error ("Argument '%s' of pure function '%s' at %L must be "
-		       "INTENT(IN) or VALUE", sym->name, proc->name,
-		       &sym->declared_at);
+	  if (proc->attr.function && sym->attr.intent != INTENT_IN)
+	    {
+	      if (sym->attr.value)
+		gfc_notify_std (GFC_STD_F2008, "Fortran 2008: Argument '%s' "
+				"of pure function '%s' at %L with VALUE "
+				"attribute but without INTENT(IN)", sym->name,
+				proc->name, &sym->declared_at);
+	      else
+		gfc_error ("Argument '%s' of pure function '%s' at %L must be "
+			   "INTENT(IN) or VALUE", sym->name, proc->name,
+			   &sym->declared_at);
+	    }
 
-	  if (proc->attr.subroutine && sym->attr.intent == INTENT_UNKNOWN
-	      && !sym->attr.value)
-	    gfc_error ("Argument '%s' of pure subroutine '%s' at %L must "
+	  if (proc->attr.subroutine && sym->attr.intent == INTENT_UNKNOWN)
+	    {
+	      if (sym->attr.value)
+		gfc_notify_std (GFC_STD_F2008, "Fortran 2008: Argument '%s' "
+				"of pure subroutine '%s' at %L with VALUE "
+				"attribute but without INTENT", sym->name,
+				proc->name, &sym->declared_at);
+	      else
+		gfc_error ("Argument '%s' of pure subroutine '%s' at %L must "
 		       "have its INTENT specified or have the VALUE "
 		       "attribute", sym->name, proc->name, &sym->declared_at);
+	    }
 	}
 
       if (proc->attr.implicit_pure && !sym->attr.pointer
--- /dev/null	2011-02-01 07:33:44.195999996 +0100
+++ gcc/gcc/testsuite/gfortran.dg/pure_formal_2.f90	2011-02-01 15:05:21.000000000 +0100
@@ -0,0 +1,18 @@ 
+! { dg-do compile }
+! { dg-options "-std=f2003" }
+!
+! PR fortran/47550
+! Follow up to: PR fortran/47507
+!
+! PURE procedures: Allow arguments w/o INTENT if they are VALUE
+!
+
+pure function f(x) ! { dg-error "Fortran 2008: Argument 'x' of pure function" }
+  real, VALUE :: x
+  real :: f
+  f = sin(x)
+end function f
+
+pure subroutine sub(x) ! { dg-error "Fortran 2008: Argument 'x' of pure subroutine" }
+  real, VALUE :: x
+end subroutine sub