Fortran: Correctly handle attributes for associate names
Fixes incorrect POINTER and ALLOCATABLE attributes for Fortran associate names, aligning with F2023 standard.
This change corrects how Fortran associate names handle POINTER, ALLOCATABLE, and TARGET attributes, adhering to the F2023 standard. Previously, gfortran incorrectly granted polymorphic associate names the POINTER attribute of their class container, enabling invalid pointer assignments. The fix ensures associate names (except for SELECT RANK) do not inherit POINTER or ALLOCATABLE attributes and correctly derive TARGET from SELECT TYPE selectors.
In Details
Fortran's ASSOCIATE construct allows local names to refer to selected components or variables. According to F2023 11.1.3.3, an associate name does not inherently have POINTER or ALLOCATABLE attributes. This patch corrects gfortran's behavior, which previously assigned the POINTER attribute to polymorphic associate names based on their class container, leading to incorrect behavior in pointer assignment and within TYPE IS blocks. The TARGET attribute is now sourced from the SELECT TYPE selector itself, not its data component.
- ASSOCIATE construct
- A Fortran construct that allows defining local names that refer to selected components or variables within a specific scope.
- POINTER attribute
- In Fortran, this attribute declares a variable as a pointer, which can be associated with a target variable or memory location.
- ALLOCATABLE attribute
- In Fortran, this attribute declares a variable whose storage can be dynamically allocated and deallocated during program execution.
- TARGET attribute
- In Fortran, this attribute indicates that a variable can be pointed to by a pointer.
- gfortran
- The GNU Fortran compiler, part of the GCC compiler suite.
- Polymorphic
- In Fortran, a variable is polymorphic if it can hold values of different intrinsic types or derived types, typically used with
SELECT TYPE. - SELECT TYPE construct
- A Fortran construct that allows conditional execution based on the dynamic type of a variable, often used with polymorphic variables.