This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/68218] ALLOCATE with size given by a module function
- From: "anlauf at gmx dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 05 Nov 2015 08:13:54 +0000
- Subject: [Bug fortran/68218] ALLOCATE with size given by a module function
- Auto-submitted: auto-generated
- References: <bug-68218-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68218
Harald Anlauf <anlauf at gmx dot de> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |anlauf at gmx dot de
--- Comment #2 from Harald Anlauf <anlauf at gmx dot de> ---
This jewel is really funny.
Extending the testcase in comment #0:
MODULE mo_test
implicit none
integer :: n = 0
CONTAINS
FUNCTION nquery()
INTEGER :: nquery
n = n + 1
WRITE (0,*) "hello #", n
nquery = n
END FUNCTION nquery
END MODULE mo_test
! ----------------------------------------------------------------------
! MAIN PROGRAM
! ----------------------------------------------------------------------
PROGRAM example
USE mo_test
implicit none
INTEGER, ALLOCATABLE :: query_buf(:)
ALLOCATE(query_buf(nquery()))
print *, "n, size (query_buf) =", n, size (query_buf)
if (n /= 1 .or. size (query_buf) /= n) print *, "ERROR!"
END PROGRAM example
one finds:
4.3, 4.6:
hello # 1
hello # 2
hello # 3
hello # 4
n, size (query_buf) = 4 1
ERROR!
4.7 and newer:
hello # 1
hello # 2
hello # 3
hello # 4
n, size (query_buf) = 4 4
ERROR!
Looking at the dump tree, there is no temporary generated for the function
result.
If one was interested only in the size of query_buf, this would be technically
a regression...