https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110826
Bug ID: 110826
Summary: Fortran array of derived type with a pointer to
function with dimensional arguments
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: mysecmailboks at gmail dot com
Target Milestone: ---
The following program fails at `func_array(1)%f => zero_state`:
```
program test_func_array
implicit none
type pp
procedure(func_template), pointer, nopass :: f =>null()
end type pp
abstract interface
function func_template(state) result(dstate)
implicit none
real, dimension(:,:), intent(in) :: state
real, dimension(size(state,1), size(state,2)) :: dstate
end function
end interface
type(pp) :: func_array(4)
real, dimension(4,6) :: state
func_array(1)%f => zero_state
print*,func_array(1)%f(state)
contains
function zero_state(state) result(dstate)
implicit none
real, dimension(:,:), intent(in) :: state
real, dimension(size(state,1), size(state,2)) :: dstate
dstate = 0.
end function zero_state
end program test_func_array
```
I have tested with various `gfortran` compilers at https://godbolt.org/. The
error is roughly the same. Along the lines of:
```
f951: internal compiler error: spec_dimen_size(): Bad dimension
0x75ee87 gfc_internal_error(char const*, ...)
???:0
0x72a016 spec_dimen_size(gfc_array_spec*, int, __mpz_struct (*) [1])
???:0
0x7d4bcb gfc_expression_rank(gfc_expr*)
???:0
0x7de37b gfc_resolve_code(gfc_code*, gfc_namespace*)
???:0
0x7c7500 gfc_parse_file()
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
ASM generation compiler returned: 1
f951: internal compiler error: spec_dimen_size(): Bad dimension
0x75ee87 gfc_internal_error(char const*, ...)
???:0
0x72a016 spec_dimen_size(gfc_array_spec*, int, __mpz_struct (*) [1])
???:0
0x7d4bcb gfc_expression_rank(gfc_expr*)
???:0
0x7de37b gfc_resolve_code(gfc_code*, gfc_namespace*)
???:0
0x7c7500 gfc_parse_file()
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Execution build compiler returned: 1
```
The same error is given even if the dimensional arguments are explicitly
defined (as opposed to using `size`).
The program works if func_array is a scalar:
```
type(pp) :: func_array
real, dimension(4,6) :: state
func_array%f => zero_state
print*,func_array%f(state)
```