GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
fortran

Fortran: Fix duplicated finalization for derived-type assignments

Corrects a bug causing duplicated finalization in derived-type assignments with component assignments.

A regression in Fortran (versions 13-17) caused duplicated finalization during intrinsic derived-type assignments that involved component assignments. This fix ensures that only one finalization occurs for the LHS, and subsequent component assignments correctly operate on the finalized value, preventing issues with temporary copies and stale data.

In Details

The generate_component_assignments function in resolve.cc incorrectly generated both a whole-derived-type assignment and a separate defined-assignment call for components when handling intrinsic assignment to a derived type with component assignment. This led to double finalization. For scalar LHS without pointer or allocatable components, the assignment now uses a finalize_only mechanism, performing a finalization of the LHS structure first, followed by individual component assignments. This avoids finalizing a stale temporary copy of the LHS.

For Context
finalization
The process of releasing resources held by a Fortran variable, typically when it goes out of scope or is deallocated. For derived types, this may involve recursive finalization of components.
derived type
A user-defined composite data type in Fortran, similar to a struct in C or a class in C++.
intrinsic assignment
The default assignment operation provided by Fortran for basic data types and derived types, following specific rules.
component assignment
Assignment to a specific component (field) within a derived type.
Filed Under: fortrancompiler bugassignment