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

            Bug ID: 122434
           Summary: Rejects allocation inside associate block in pure
                    separate module subprogram
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: damian at archaeologic dot codes
  Target Milestone: ---

Several trivial changes eliminate the compiler error message below, including
1. Moving the ALLOCATE statement outside of the ASSOCIATE block,
2. Repeating the interface information in the procedure definition,
3. Removing the RESULT clause and naming the result after the function.

$ cat neuron_m.f90 
module neuron_m
  implicit none

  type neuron_t
    real, allocatable :: weight_
  end type

  interface
    type(neuron_t) pure module function from_json() result(neuron)
    end function
  end interface

contains
  module procedure from_json
    associate(num_inputs => 1)
      allocate(neuron%weight_, source=0.)
    end associate
  end procedure
end module

$ gfortran -c neuron_m.f90 
neuron_m.f90:16:30:

   16 |       allocate(neuron%weight_, source=0.)
      |                              1
Error: Bad allocate-object at (1) for a PURE procedure

$ gfortran --version
GNU Fortran (GCC) 16.0.0 20251026 (experimental)

Reply via email to