From b5c26787c4e5d7b13df865edb7439a875c844cfe Mon Sep 17 00:00:00 2001 From: Janus Weil Date: Sat, 9 Mar 2019 19:25:39 +0100 Subject: [PATCH] re PR fortran/84504 ([F08] procedure pointer variables cannot be initialized with functions returning pointers) fix PR 84504 2019-03-09 Janus Weil PR fortran/84504 * expr.c (gfc_check_assign_symbol): Deal with procedure pointers to pointer-valued functions. 2019-03-09 Janus Weil PR fortran/84504 * gfortran.dg/pointer_init_10.f90: New test case. From-SVN: r269529 --- gcc/fortran/ChangeLog | 6 +++++ gcc/fortran/expr.c | 2 +- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gfortran.dg/pointer_init_10.f90 | 24 +++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/pointer_init_10.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 48ab06b0a18..40b3a3247f8 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2019-03-09 Janus Weil + + PR fortran/84504 + * expr.c (gfc_check_assign_symbol): Deal with procedure pointers to + pointer-valued functions. + 2019-03-09 Thomas König PR fortran/71203 diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 51552a79cde..4e95f243661 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -4321,7 +4321,7 @@ gfc_check_assign_symbol (gfc_symbol *sym, gfc_component *comp, gfc_expr *rvalue) if (!r) return r; - if (pointer && rvalue->expr_type != EXPR_NULL) + if (pointer && rvalue->expr_type != EXPR_NULL && !proc_pointer) { /* F08:C461. Additional checks for pointer initialization. */ symbol_attribute attr; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 003fe1cd702..a2eec5e7448 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-03-09 Janus Weil + + PR fortran/84504 + * gfortran.dg/pointer_init_10.f90: New test case. + 2019-03-09 John David Anglin * gfortran.dg/ieee/ieee_9.f90: Fix typo. diff --git a/gcc/testsuite/gfortran.dg/pointer_init_10.f90 b/gcc/testsuite/gfortran.dg/pointer_init_10.f90 new file mode 100644 index 00000000000..81e7d73755f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pointer_init_10.f90 @@ -0,0 +1,24 @@ +! { dg-do run } +! +! PR 84504: [F08] procedure pointer variables cannot be initialized with functions returning pointers +! +! Contributed by Sriram Swaminarayan + +module test_mod + implicit none + private + integer, target :: i = 333 + procedure(the_proc), pointer, public :: ptr => the_proc +contains + function the_proc() + integer, pointer :: the_proc + the_proc => i + end function +end module + +program test_prog + use test_mod + integer, pointer :: ip + ip => ptr() + if (ip /= 333) stop 1 +end -- 2.30.2