https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102641
Bug ID: 102641 Summary: Bogus error for intent(out) dummy that is a polymorphic assumed-rank array Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: sandra at gcc dot gnu.org Target Milestone: --- A trivial subroutine with a intent(out) dummy that is a polymorphic assumed-rank array... module m contains subroutine s1 (x, y) class(*) :: x(..) class(*), intent (out) :: y(..) end subroutine end module ...incorrectly produces a compilation error: unlimited1.f90:4:23: 4 | subroutine s1 (x, y) | 1 Error: Assumed-rank variable y at (1) may only be used as actual argument This error is arising from references to the intent(out) argument in the automatically-generated deallocation and initialization code. Probably some flag needs to be added to the references in that code to suppress the warning, which is coming from resolve_variable in resolve.c. Of course runtime testing is needed as well to ensure that the generated initialization code DTRT with assumed-rank arrays -- it's obviously never been tested. In fact, I wonder if the initialization code generator is even equipped to handle arrays whose rank is unknown at compile time. (I'm not familiar with the code to implement it, but I see a loop nest coming out of the front end for fixed-rank arrays.) I ran into this error while working on PR 54753 (diagnostic for C839 involving assumed-size actual arguments passed to assumed-rank dummies), but it's a different issue unrelated to invalid calls, so I'm giving it its own issue. The patch Tobias already committed that was tagged PR 54753 only fixed interface declarations by suppressing the unused initialization code entirely, as a workaround to unblock testing of the actual fix for PR 54753.