re PR fortran/67884 (Missing error message on required allocatable attribute)
authorSteven G. Kargl <kargl@gcc.gnu.org>
Fri, 21 Jun 2019 20:24:01 +0000 (20:24 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Fri, 21 Jun 2019 20:24:01 +0000 (20:24 +0000)
2019-06-21  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/67884
* resolve.c (deferred_requirements) : Check only the result variable.
(resolve_fl_procedure): Check deferred requirements on functions.

2019-06-21  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/67884
* gfortran.dg/dummy_procedure_8.f90: Remove a test that is ...
* gfortran.dg/pr67884.f90: ... covered here.  New test.

From-SVN: r272569

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/dummy_procedure_8.f90
gcc/testsuite/gfortran.dg/pr67884.f90 [new file with mode: 0644]

index 6a3bd62..4289227 100644 (file)
@@ -1,5 +1,11 @@
 2019-06-21  Steven G. Kargl  <kargl@gcc.gnu.org>
 
+       PR fortran/67884
+       * resolve.c (deferred_requirements) : Check only the result variable.
+       (resolve_fl_procedure): Check deferred requirements on functions.
+
+2019-06-21  Steven G. Kargl  <kargl@gcc.gnu.org>
+
        PR fortran/51991
        * decl.c (gfc_match_save): If SAVE was not seen, return MATCH_NO
        instead issuing an error message and returning MATCH_ERROR.
index afa4e5c..af7078a 100644 (file)
@@ -12388,6 +12388,10 @@ deferred_requirements (gfc_symbol *sym)
           || sym->attr.associate_var
           || sym->attr.omp_udr_artificial_var))
     {
+      /* If a function has a result variable, only check the variable.  */
+      if (sym->result && sym->name != sym->result->name)
+       return true;
+
       gfc_error ("Entity %qs at %L has a deferred type parameter and "
                 "requires either the POINTER or ALLOCATABLE attribute",
                 sym->name, &sym->declared_at);
@@ -12598,6 +12602,10 @@ resolve_fl_procedure (gfc_symbol *sym, int mp_flag)
       && !resolve_fl_var_and_proc (sym, mp_flag))
     return false;
 
+  /* Constraints on deferred type parameter.  */
+  if (!deferred_requirements (sym))
+    return false;
+
   if (sym->ts.type == BT_CHARACTER)
     {
       gfc_charlen *cl = sym->ts.u.cl;
index b56645f..63bb7b9 100644 (file)
@@ -1,3 +1,9 @@
+2019-06-21  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/67884
+       * gfortran.dg/dummy_procedure_8.f90: Remove a test that is ...
+       * gfortran.dg/pr67884.f90: ... covered here.  New test.
+
 2019-06-21  Marek Polacek  <polacek@redhat.com>
 
        PR c++/90490 - fix decltype issues in noexcept-specifier.
index 7b8a264..603692c 100644 (file)
@@ -7,7 +7,6 @@
 implicit none
 
 call call_a(a1)  ! { dg-error "Character length mismatch in function result" }
-call call_a(a2)  ! { dg-error "Character length mismatch in function result" }
 call call_b(b1)  ! { dg-error "Shape mismatch" }
 call call_c(c1)  ! { dg-error "POINTER attribute mismatch in function result" }
 call call_d(c1)  ! { dg-error "ALLOCATABLE attribute mismatch in function result" }
@@ -19,9 +18,6 @@ contains
   character(1) function a1()
   end function
 
-  character(:) function a2()
-  end function
-
   subroutine call_a(a3)
     interface
       character(2) function a3()
diff --git a/gcc/testsuite/gfortran.dg/pr67884.f90 b/gcc/testsuite/gfortran.dg/pr67884.f90
new file mode 100644 (file)
index 0000000..d502642
--- /dev/null
@@ -0,0 +1,21 @@
+! { dg-do compile }
+! PR fortran/67884
+! Original code contribute by Gerhard Steinmetz 
+program p
+   integer i
+   print *, [(f(i), i=1,3)]
+   print *, [(g(i), i=1,3)]
+   contains
+   function f(n)              ! { dg-error "has a deferred type parameter" }
+      integer :: n
+      character(:) :: f
+      character(3) :: c = 'abc'
+      f = c(n:n)
+   end
+   function g(n) result(z)    ! { dg-error "has a deferred type parameter" }
+      integer :: n
+      character(:) :: z
+      character(3) :: c = 'abc'
+      z = c(n:n)
+   end
+end program p