https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109500

--- Comment #4 from anlauf at gcc dot gnu.org ---
I think one cannot achieve what the OP wants by using allocable function
results.  One should use a subroutine instead.

Compiling the code with the NAG compiler gives:

NAG Fortran Compiler Release 7.1(Hanzomon) Build 7101
Warning: pr109500.f90, line 7: Allocatable function F has not been allocated or
assigned a value
Error: pr109500.f90, line 2: Expected an ALLOCATABLE variable for argument P
(no. 1) of IS_ALLOCATED
[NAG Fortran Compiler error termination, 1 error, 1 warning]

Not perfect, but what you are seeing is an attempt by the compiler to do
argument association when you invoke function is_allocated.

Now look at the following variants in the main:

1)
  print *, allocated(f())

You'll get:

    2 |   print *, allocated(f())
      |                     1
Error: 'array' argument of 'allocated' intrinsic at (1) must be a variable

This is what the standard says.

2)
  integer, allocatable :: p
  p = f()
  print *, allocated(p)

This compiles, but you get a runtime error (SIGSEGV) with gfortran and ifort.

Why?  The assignment p=f() is invalid for unallocated r.h.s., and you are
hitting this.  The running program will never reach the allocated(p).

I don't see a legal way to use an allocatable function without allocating
the result.  So you should use a subroutine and allocate a result variable.

The only potential issue I see here with gfortran is that there is no working
runtime diagnostics for the non-allocated r.h.s. above.  But there is none
for current ifort/ifx either.

If the reporter agrees, we should close this PR as invalid.

Reply via email to