https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104811
Bug ID: 104811 Summary: maxloc/minloc cannot accept character arguments without `dim` optional argument. Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: a.shahmoradi at gmail dot com Target Milestone: --- The following code appears to be standard-conforming. ``` character(1) :: str(3) str = ["a", "c", "a"] print *, maxloc(str) ! requires dim = 1 argument to function. print *, minloc(str) ! requires dim = 1 argument to function. end ``` However, gfortran 11 or newer versions generate code that crashes with a segfault error at runtime, ``` Program received signal SIGSEGV: Segmentation fault - invalid memory reference. Backtrace for this error: #0 0x7faba0a82642 in ??? #1 0x7faba0a81815 in ??? #2 0x7faba070020f in ??? #3 0x7faba0c70caa in ??? #4 0x40125b in MAIN__ at /app/example.f90:3 #5 0x4010bc in main at /app/example.f90:5 ``` The above code snippet can be readily tested here to reproduce the segfault: https://godbolt.org/z/jGchG7zq3 If we add `dim = 1` to the maxloc/minloc calls, then the error is resolved. But the dim argument is optional and should not be needed. Intel ifort compiles and generates a correct answer with the above code.