https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122521
--- Comment #46 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Mikael Morin <[email protected]>: https://gcc.gnu.org/g:0540a0bac8a125c1245e18368a50acf0bcf263cf commit r17-6981-g0540a0bac8a125c1245e18368a50acf0bcf263cf Author: Mikael Morin <[email protected]> Date: Tue Dec 1 11:55:07 2026 +0100 fortran: array descriptor: Set polymorphic elem_len value [PR122521] Add an initialization of the array descriptor elem_len field with the size from the class descriptor, and for CHARACTER dynamic types the string length, when associating a polymorphic scalar with a polymorphic assumed- rank dummy. Before this change, the array descriptor element length field was not set after the initialization of the dtype with a constructor of constant values. This means the element length was set to the only value known at compile time, the size of the declared type. This change adds an assignment setting the elem_len field after the dtype initialization, using the value from the class descriptor. The elem_len initialization is not removed from the dtype initialization, so that it is the declared type size that prevails instead of an unitialized value when the actual reference is absent, unallocated or unassociated. PR fortran/122521 PR fortran/127384 gcc/fortran/ChangeLog: * trans-descriptor.cc (gfc_set_descriptor_from_scalar_class): Add an initialization of the element length with the size from the class descriptor, and for CHARACTER dynamic types the string length. gcc/testsuite/ChangeLog: * gfortran.dg/sizeof_8.f90: New test. * gfortran.dg/sizeof_9.f90: New test.
