forked from wangliu-iscas/gcc-patch
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fortran: function results never have the ALLOCATABLE attribute [PR109…
…500] Fortran 2018 8.5.3 (ALLOCATABLE attribute) explains in Note 1 that the result of referencing a function whose result variable has the ALLOCATABLE attribute is a value that does not itself have the ALLOCATABLE attribute. gcc/fortran/ChangeLog: PR fortran/109500 * interface.cc (gfc_compare_actual_formal): Reject allocatable functions being used as actual argument for allocable dummy. gcc/testsuite/ChangeLog: PR fortran/109500 * gfortran.dg/allocatable_function_11.f90: New test. Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
- Loading branch information
1 parent
afc7e20
commit 7f56c10
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
! { dg-do compile } | ||
! PR fortran/109500 - check F2018:8.5.3 Note 1 | ||
! | ||
! The result of referencing a function whose result variable has the | ||
! ALLOCATABLE attribute is a value that does not itself have the | ||
! ALLOCATABLE attribute. | ||
|
||
program main | ||
implicit none | ||
integer, allocatable :: p | ||
procedure(f), pointer :: pp | ||
pp => f | ||
p = f() | ||
print *, allocated (p) | ||
print *, is_allocated (p) | ||
print *, is_allocated (f()) ! { dg-error "is a function result" } | ||
print *, is_allocated (pp()) ! { dg-error "is a function result" } | ||
call s (p) | ||
call s (f()) ! { dg-error "is a function result" } | ||
call s (pp()) ! { dg-error "is a function result" } | ||
|
||
contains | ||
subroutine s(p) | ||
integer, allocatable :: p | ||
end subroutine s | ||
|
||
function f() | ||
integer, allocatable :: f | ||
allocate (f, source=42) | ||
end function | ||
|
||
logical function is_allocated(p) | ||
integer, allocatable :: p | ||
is_allocated = allocated(p) | ||
end function | ||
end program |