GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc/fortran

Fortran: Fix parameterized derived type errors

Improves handling of parameterized derived types in Fortran by correcting how component initializers and lengths are simplified.

This commit refines the handling of parameterized derived types (PDTs) in the Fortran compiler by adjusting how component inquiries and string lengths are processed. It changes the approach for finding component initializers to use a KIND expression and gfc_simplify_len, which simplifies the logic for accessing original code and handling variable string lengths. This change improves robustness when dealing with PDTs that have lengths defined by variables.

In Details

This patch in gcc/fortran addresses PR82173 concerning Parameterized Derived Types (PDTs). It modifies expr.cc's find_inquiry_ref to use gfc_simplify_len after constructing a KIND expression, rather than directly calling gfc_pdt_find_component_copy_initializer. The gfc_simplify_len function is enhanced to better handle PDT string lengths that are variables, simplifying the logic by storing the variable name and inserting parameter expressions when necessary. This aims to resolve issues where the length simplification might not have produced a constant expression correctly.

For Context
Parameterized Derived Type (PDT)
A derived type in Fortran whose components or other attributes can be specified by parameters at the time of type instantiation, similar to templates in C++ or generic types in other languages.
Fortran gfc
The internal representation and processing framework used by the GNU Fortran compiler (gfortran) to manage Fortran source code during compilation.
inquiry reference
In Fortran, an inquiry refers to a intrinsic function or a type attribute that returns information about a variable or type, such as its length or kind. An inquiry reference is an expression that invokes such an inquiry.
KIND expression
In Fortran, KIND specifies the properties of intrinsic data types, such as precision or range. A KIND expression is used to determine the KIND value for a type.
Filed Under: fortrancompiler bugs