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.
This commit is contained in:
parent
e42b672f52
commit
58e7732a2f
4 changed files with 90 additions and 18 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
29
gcc/testsuite/gfortran.dg/PR94104a.f90
Normal file
29
gcc/testsuite/gfortran.dg/PR94104a.f90
Normal file
|
@ -0,0 +1,29 @@
|
|||
! { dg-do compile }
|
||||
! { dg-options "-std=f2003" }
|
||||
!
|
||||
! PR fortran/94104
|
||||
!
|
||||
|
||||
program diag_p
|
||||
implicit none
|
||||
|
||||
integer, parameter :: n = 7
|
||||
|
||||
integer :: a(n)
|
||||
integer, target :: b(n)
|
||||
|
||||
a = 1
|
||||
print *, sumf(a) ! { dg-error "Actual argument for 'a' at .1. must be a pointer" }
|
||||
print *, sumf(b) ! { dg-error "Fortran 2008: Non-pointer actual argument at .1. to pointer dummy 'a'" }
|
||||
|
||||
contains
|
||||
|
||||
function sumf(a) result(s)
|
||||
integer, pointer, intent(in) :: a(:)
|
||||
|
||||
integer :: s
|
||||
|
||||
s = sum(a)
|
||||
end function sumf
|
||||
|
||||
end program diag_p
|
29
gcc/testsuite/gfortran.dg/PR94104b.f90
Normal file
29
gcc/testsuite/gfortran.dg/PR94104b.f90
Normal file
|
@ -0,0 +1,29 @@
|
|||
! { dg-do compile }
|
||||
! { dg-options "-std=f2008" }
|
||||
!
|
||||
! PR fortran/94104
|
||||
!
|
||||
|
||||
program diag_p
|
||||
implicit none
|
||||
|
||||
integer, parameter :: n = 7
|
||||
|
||||
integer :: a(n)
|
||||
integer, target :: b(n)
|
||||
|
||||
a = 1
|
||||
print *, sumf(a) ! { dg-error "Actual argument for 'a' at .1. must be a pointer or a valid target" }
|
||||
print *, sumf(b)
|
||||
|
||||
contains
|
||||
|
||||
function sumf(a) result(s)
|
||||
integer, pointer, intent(in) :: a(:)
|
||||
|
||||
integer :: s
|
||||
|
||||
s = sum(a)
|
||||
end function sumf
|
||||
|
||||
end program diag_p
|
|
@ -2,7 +2,7 @@
|
|||
! { dg-do compile }
|
||||
! Originally contributed by Joost VandeVondele
|
||||
INTEGER, POINTER :: I
|
||||
CALL S1((I)) ! { dg-error "Actual argument for .i. must be a pointer" }
|
||||
CALL S1((I)) ! { dg-error "Actual argument for .i. at .1. must be a pointer or a valid target" }
|
||||
CONTAINS
|
||||
SUBROUTINE S1(I)
|
||||
INTEGER, POINTER ::I
|
||||
|
|
Loading…
Add table
Reference in a new issue