From: Steven G. Kargl Date: Fri, 21 Jun 2019 20:24:01 +0000 (+0000) Subject: re PR fortran/67884 (Missing error message on required allocatable attribute) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9b15893c31a9fd926459123037c09b0ac64a5bd3;p=gcc.git re PR fortran/67884 (Missing error message on required allocatable attribute) 2019-06-21 Steven G. Kargl 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 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 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 6a3bd62e774..42892276dbd 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2019-06-21 Steven G. Kargl + + 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 PR fortran/51991 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index afa4e5c2ccf..af7078a46d9 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b56645fc0cf..63bb7b94e7b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-06-21 Steven G. Kargl + + 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 PR c++/90490 - fix decltype issues in noexcept-specifier. diff --git a/gcc/testsuite/gfortran.dg/dummy_procedure_8.f90 b/gcc/testsuite/gfortran.dg/dummy_procedure_8.f90 index 7b8a2645f76..603692c18b9 100644 --- a/gcc/testsuite/gfortran.dg/dummy_procedure_8.f90 +++ b/gcc/testsuite/gfortran.dg/dummy_procedure_8.f90 @@ -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 index 00000000000..d50264240b3 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr67884.f90 @@ -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