[flang-commits] [flang] [flang] Rework component KIND= values in PDT instantiations (PR #162367)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Wed Oct 8 13:04:44 PDT 2025
klausler wrote:
> > > The full test case of the reducer is indeed fixed. Thanks!
> > > The following is for the LEN= parameter of the character type.
> > > ```
> > > type base
> > > character(2) :: c1
> > > integer(2) :: i1
> > > character(kind(i1)) :: c2
> > > character(len(c1)) :: c3
> > > end type
> > > type(base) :: b1
> > > print*, b1%c1%len
> > > print*, b1%c2%len
> > > print*, b1%c3%len
> > > end
> > > ```
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > The expected output
> > > ```
> > > > a.out
> > > 2
> > > 2
> > > 2
> > > ```
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > But Flang failed to compile it.
> > > Should I open a new issue?
> >
> >
> > No; it's not valid Fortran. You can't refer to components in a derived type definition, only to type parameters and to the type itself.
>
> The code is inquiring the length type parameter of component `c1` though, the same way to inquire the kind parameter of `i1`. Both are constant expression is this case.
I don't think so. Rather, `kind(i1)` is returning the kind of an implicitly typed (integer) variable `i1` in the enclosing scope, and `len(c1)` is attempting to extract the character length of an implicitly typed (real) variable `c1` in the enclosing scope.
https://github.com/llvm/llvm-project/pull/162367
More information about the flang-commits
mailing list