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

Fortran: Array constructor is not polymorphic without type-spec

Fixes Fortran array constructors to correctly handle polymorphic types.

This commit corrects the behavior of Fortran array constructors that lack a type-specifier. Previously, such constructors defaulted to the type of their first element, leading to issues when used with polymorphic (CLASS) types. This could result in compiler internal errors (ICEs) during allocation or incorrect type checking. The change ensures that an untyped array constructor correctly assumes the declared type of a CLASS value and enforces that all elements match this type, resolving ICEs and aligning with F2023 standards.

In Details

The Fortran front-end's check_element_type function in array.cc has been updated to correctly handle array constructors without an explicit type-spec. Previously, these defaulted to the declared type of the first element, causing problems with polymorphic (CLASS) types, particularly when used with ALLOCATE(SOURCE=...). This fix enforces that such constructors adopt the declared type of a CLASS value and requires all elements to share that declared type, resolving ICEs reported in PRs 127541 and 53653.

For Context
array constructor
A Fortran language construct used to create an array by specifying its elements within parentheses.
type-spec
In Fortran, a declaration specifying the data type of a variable or construct.
CLASS(*)
In Fortran, a type specifier for an unlimited polymorphic variable, which can hold values of any type.
declared type
The type specified for a variable at compile time.
dynamic type
The actual type of a value at runtime, which may differ from its declared type for polymorphic variables.
ICE
Internal Compiler Error. An unexpected condition encountered by the compiler during translation, usually indicating a bug.
Filed Under: fortranpolymorphismarray constructorcompiler error