diff options
author | José Rui Faustino de Sousa <jrfsousa@gmail.com> | 2022-11-09 21:30:25 +0100 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2022-11-13 21:19:18 +0100 |
commit | 58e7732a2feddf475e72b232bf16494d84a41acf (patch) | |
tree | d006a24299c75d0b49ee8e1f822046e7dfca0580 /gcc/fortran/interface.cc | |
parent | e42b672f5297594fff4b82064c5386fbb0ae1ff3 (diff) | |
download | gcc-58e7732a2feddf475e72b232bf16494d84a41acf.zip gcc-58e7732a2feddf475e72b232bf16494d84a41acf.tar.gz gcc-58e7732a2feddf475e72b232bf16494d84a41acf.tar.bz2 |
Fortran: diagnostics for actual arguments to pointer dummy arguments [PR94104]
Error message improvement. In Fortran 2008 actual procedure arguments
associated with a pointer, intent(in) attribute, dummy argument
can also have the target attribute, not just pointer.
gcc/fortran/ChangeLog:
PR fortran/94104
* interface.cc (gfc_compare_actual_formal): Improve error message
dependent on Fortran standard level.
gcc/testsuite/ChangeLog:
PR fortran/94104
* gfortran.dg/parens_2.f90: Adjust to improved error message.
* gfortran.dg/PR94104a.f90: New test.
* gfortran.dg/PR94104b.f90: New test.
Diffstat (limited to 'gcc/fortran/interface.cc')
-rw-r--r-- | gcc/fortran/interface.cc | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc index d3e1995..49dbd1d 100644 --- a/gcc/fortran/interface.cc +++ b/gcc/fortran/interface.cc @@ -3477,25 +3477,39 @@ gfc_compare_actual_formal (gfc_actual_arglist **ap, gfc_formal_arglist *formal, goto match; } - if (a->expr->expr_type != EXPR_NULL - && compare_pointer (f->sym, a->expr) == 0) + if (a->expr->expr_type != EXPR_NULL) { - if (where) - gfc_error ("Actual argument for %qs must be a pointer at %L", - f->sym->name, &a->expr->where); - ok = false; - goto match; - } + int cmp = compare_pointer (f->sym, a->expr); + bool pre2008 = ((gfc_option.allow_std & GFC_STD_F2008) == 0); - if (a->expr->expr_type != EXPR_NULL - && (gfc_option.allow_std & GFC_STD_F2008) == 0 - && compare_pointer (f->sym, a->expr) == 2) - { - if (where) - gfc_error ("Fortran 2008: Non-pointer actual argument at %L to " - "pointer dummy %qs", &a->expr->where,f->sym->name); - ok = false; - goto match; + if (pre2008 && cmp == 0) + { + if (where) + gfc_error ("Actual argument for %qs at %L must be a pointer", + f->sym->name, &a->expr->where); + ok = false; + goto match; + } + + if (pre2008 && cmp == 2) + { + if (where) + gfc_error ("Fortran 2008: Non-pointer actual argument at %L to " + "pointer dummy %qs", &a->expr->where, f->sym->name); + ok = false; + goto match; + } + + if (!pre2008 && cmp == 0) + { + if (where) + gfc_error ("Actual argument for %qs at %L must be a pointer " + "or a valid target for the dummy pointer in a " + "pointer assignment statement", + f->sym->name, &a->expr->where); + ok = false; + goto match; + } } |