Hi Jerry, This patch needs --ignore-whitespace to apply successfully. However once applied, it passes regression testing and even fixes the original problem :-)
OK for mainline. Thanks for the patch. Paul On Sun, 15 Nov 2026 at 01:29, Jerry DeLisle <[email protected]> wrote: > > See attached patch. gfortran represents a polymorphic associate name by > a class container, and gfc_variable_attr gave the associate name that > container's POINTER attribute. In a TYPE IS block the associate name > refers to the selector through the hidden _data component, which is > always a pointer, so the TARGET check also saw a pointer. The patch > clears POINTER and ALLOCATABLE for every associate name except that of > SELECT RANK, and looks through _data to the selector for TARGET. Trunk > reports four of the seven errors in the new test pr54322.f90; with the > patch it reports all seven, at the same lines as flang. > > The fix is in gfc_variable_attr in primary.cc; the rest is tests. > associate_42.f90 pointer-assigned the associate name. It now > pointer-assigns obj%p after END ASSOCIATE rather than inside the > block, because inside the block END ASSOCIATE undoes the assignment > (PR128735). select_type_30.f03 passed an associate name to a POINTER > dummy, which is valid only if the dummy is INTENT(IN). > > Regression tested on x86_64. > > OK for mainline? > > Regards, > > Jerry > > --- > > fortran: [PR54322] Associate names are neither POINTER nor ALLOCATABLE > > An associate name has neither the POINTER nor the ALLOCATABLE attribute, > and has the TARGET attribute only if the selector is a variable with the > TARGET or POINTER attribute (F2023 11.1.3.3). gfortran gave a > polymorphic associate name the POINTER attribute of its class container, > so it accepted pointer assignment to the associate name and, in a TYPE > IS block, pointer assignment to it from a selector that was neither > TARGET nor POINTER. > > Clear POINTER and ALLOCATABLE for an associate name other than that of > SELECT RANK, and take TARGET from a SELECT TYPE selector rather than > from the _data component that narrows it. Two tests relied on the old > behavior: associate_42.f90 pointer-assigned an associate name, and > select_type_30.f03 passed one to a POINTER dummy without INTENT(IN). > > Assisted-by: Claude Opus 5.5 > > PR fortran/54322 > > gcc/fortran/ChangeLog: > > * primary.cc (gfc_variable_attr): Clear POINTER and ALLOCATABLE for > an associate name, except for SELECT RANK. Take TARGET from a > SELECT TYPE selector rather than from its _data component. > > gcc/testsuite/ChangeLog: > > * gfortran.dg/associate_42.f90: Pointer-assign the selector, not > the associate name. > * gfortran.dg/select_type_30.f03: Make the POINTER dummy > INTENT(IN). > * gfortran.dg/pr54322.f90: New test.
