https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111521
Bug ID: 111521 Summary: Polymorphic variable loses information about the actual type assigned when passed as function result Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: dcesari69 at gmail dot com Target Milestone: --- Created attachment 55961 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55961&action=edit Program showing the described behavior Hello, the attached program shows an anomalous behavior since gcc-gfortran version 13, in the previous gfortran versions it worked as expected. gcc version: GNU Fortran (GCC) 13.2.1 20230728 (Red Hat 13.2.1-1) Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. OS (Fedora 38): Linux trentotto 6.3.8-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jun 15 02:15:40 UTC 2023 x86_64 GNU/Linux Build command line: gfortran -g -fcheck=all -o testpoli testpoli.f90 Actual program stdout: 1.integer 1.integer 2.unknown type 3.unknown type 8 -1 Expected program stdout (e.g. when compiled with gfortran 12.2.1): 1.integer 2.integer 3.integer 8 8 Description: The unlimited polymorphic derived type member %val is initialised with an integer, but when passed back as a result of a chain of functions, it loses its type. Additionally, the debugging print show that the function link_getval is apparently executed twice, while it is called only once. By executing the commented line `v => this%curr%getval()` instead of `v => this%getcurr()` the program gives the expected result with version 13, however the original code was obviously more complex and this chained function call was necessary. The bug could be somehow related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110415 also appearing in version 13.