[Bug fortran/102333] Invalid PROCEDURE statement accepted.
albert at tugraz dot at
gcc-bugzilla@gcc.gnu.org
Sun Mar 29 21:37:36 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102333
--- Comment #24 from Christopher Albert <albert at tugraz dot at> ---
(In reply to anlauf@gcc.gnu.org from comment #22)
> The following tiny variation of the testcase in comment#1 produces a
> partially misleading error:
>
> function f(x) result(y)
> class(*), allocatable :: y
> contains
> function g()
> procedure(f), allocatable :: g
> end
> end
>
> pr102333.f90:5:36:
>
> 5 | procedure(f), allocatable :: g
> | 1
> Error: Procedure pointer result 'g' at (1) is missing the pointer attribute
The misleading error comes from add_hidden_procptr_result in
match_procedure_decl. When the declared name matches the function name (making
it a result), it redirects to a hidden ppr@ symbol that copies pointer,
external, etc. but not allocatable. So gfc_add_proc's later gfc_check_conflict
never sees the PROCEDURE/ALLOCATABLE conflict, and resolve.cc eventually finds
the ppr@ without a pointer and emits the wrong diagnostic.
Fix is to catch the conflict early in match_procedure_decl, before
add_hidden_procptr_result can lose the attribute. With this, the comment #22
variation gives:
Error: PROCEDURE attribute conflicts with ALLOCATABLE attribute at (1)
Regtested with full check-gfortran, no regressions.
More information about the Gcc-bugs
mailing list