GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
fortran

Fortran: Fix character length checking for array element arguments.

The Fortran compiler now correctly checks character lengths when passing array element arguments to character dummy arguments.

The Fortran compiler’s character length checking has been improved when passing array elements as arguments to character dummy arguments. Previously, the compiler incorrectly estimated the storage size based on the entire array, leading to bogus warnings. The fix now compares the actual character lengths, preventing false positives when the dummy argument is a scalar character type. A new test case has been added to verify the fix.

In Details

This commit addresses PR125393 by fixing a bug in gfc_compare_actual_formal within interface.cc. The issue occurred when passing a character array element to a scalar character dummy argument. The compiler was incorrectly using the storage size of the remaining array elements instead of the actual character length of the element, leading to spurious warnings. The fix ensures that the character lengths are compared directly in this case.

For Context

In Fortran, dummy arguments are the parameters declared in a subroutine or function definition, while actual arguments are the expressions passed when the subroutine or function is called. When a character variable is passed as an argument, the compiler must ensure that the length of the actual argument matches the expected length of the dummy argument. This helps prevent buffer overflows and other memory-related errors. This is a correctness fix, preventing bogus warnings during compilation.

Filed Under: fortranargument checkingcompiler