https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108921
Bug ID: 108921
Summary: ICE: using the result of an impure function in
automatic character allocation
Product: gcc
Version: 12.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: vterzi1996 at gmail dot com
Target Milestone: ---
Created attachment 54527
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54527&action=edit
Complete backtrace
Consider the following minimal working example:
```
module lib
type t
contains
procedure::f,g
end type
contains
integer function f(this)
class(t),intent(in)::this
f=10
end
function g(this)result(r)
class(t),intent(in)::this
character(len=this%f())::r ! problem appears here
r='42'
end
end
program prog
use lib
type(t)::o
print*,o%g()
end
```
This example was already discussed here:
https://stackoverflow.com/questions/75544072/using-function-result-as-character-length-in-fortran
The compilation of this code with the GNU compiler (gfortran 12.2.0 on Rocky
Linux 8.7) fails with the message `f951: internal compiler error: Segmentation
fault` (full output is in the attachment). It also fails with 7.5.0, 9.4.0, and
11.1.0 on Ubuntu 18.04.2 LTS. The reason for this problem is the unallowed
usage of the result of an impure function (here: `f`) in the automatic
allocation of the CHARACTER variable, but the compiler fails to identify the
mistake in the code.