https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121564
Bug ID: 121564 Summary: Segmentation fault when function returns pointer to a derived type with pointer components Product: gcc Version: 15.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: baldur.paulwitz at web dot de Target Milestone: --- Created attachment 62125 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62125&action=edit Minimal example This program demonstrates a suspected bug or a dangerous language pitfall in Fortran. A segmentation fault occurs when a FUNCTION returns a pointer to a derived type that has pointer components. The crash occurs even with all compiler optimizations disabled (-O0). The crash does NOT occur if the pointer is returned via a SUBROUTINE with an intent(out) argument. This suggests an issue with the handling of the temporary variable used for the function's return value, possibly leading to a dangling pointer for the nested, heap-allocated components of the derived type.