This patch fixes the result check for coarrays / variables with coarray subcomponents. It was working with a separate RESULT() variable - but not if the function name was the result variable.

Build and regtested on x86-64-linux.
OK for the trunk?

Tobias
2011-08-04  Tobias Burnus  <bur...@net-b.de>

	* resolve.c (resolve_symbol): Fix coarray result-var check.

2011-08-04  Tobias Burnus  <bur...@net-b.de>

	* gfortran.dg/coarray_26.f90: New.

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index b8a8ebb..4401ea5 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -12440,10 +12440,10 @@ resolve_symbol (gfc_symbol *sym)
     gfc_error ("Dummy argument '%s' at %L of LOCK_TYPE shall not be "
 	       "INTENT(OUT)", sym->name, &sym->declared_at);
 
-  /* F2008, C526.  */
+  /* F2008, C525.  */
   if (((sym->ts.type == BT_DERIVED && sym->ts.u.derived->attr.coarray_comp)
        || sym->attr.codimension)
-      && sym->attr.result)
+      && (sym->attr.result || sym->result == sym))
     gfc_error ("Function result '%s' at %L shall not be a coarray or have "
 	       "a coarray component", sym->name, &sym->declared_at);
 
--- /dev/null	2011-08-04 08:03:55.531886509 +0200
+++ gcc/gcc/testsuite/gfortran.dg/coarray_26.f90	2011-08-04 16:33:40.000000000 +0200
@@ -0,0 +1,53 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=single" }
+!
+! Coarray declaration constraint checks
+!
+
+function foo3a() result(res)
+  implicit none
+  integer :: res
+  codimension :: res[*] ! { dg-error "CODIMENSION attribute conflicts with RESULT" }
+end
+
+function foo2a() result(res)
+  integer :: res[*] ! { dg-error "CODIMENSION attribute conflicts with RESULT" }
+end
+
+function fooa() result(res) ! { dg-error "shall not be a coarray or have a coarray component" }
+  implicit none
+  type t
+    integer, allocatable :: A[:]
+  end type t
+  type(t):: res
+end
+
+function foo3() ! { dg-error "shall not be a coarray or have a coarray component" }
+  implicit none
+  integer :: foo3
+  codimension :: foo3[*]
+end
+
+function foo2() ! { dg-error "shall not be a coarray or have a coarray component" }
+  implicit none
+  integer :: foo2[*]
+end
+
+function foo() ! { dg-error "shall not be a coarray or have a coarray component" }
+  type t
+    integer, allocatable :: A[:]
+  end type t
+  type(t):: foo
+end
+
+subroutine test()
+  use iso_c_binding
+  implicit none
+  type(c_ptr), save :: caf[*] ! { dg-error "shall not be a coarray" }
+end subroutine test
+
+subroutine test2()
+  use iso_c_binding
+  implicit none
+  type(c_funptr), save :: caf[*] ! { dg-error "shall not be a coarray" }
+end subroutine test2

Reply via email to