[Bug fortran/117070] Procedure target error with parameter structure constructor
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117070 --- Comment #9 from anlauf at gcc dot gnu.org --- Note that type(pc), parameter :: ... does not yet fully work, see commented parts of the testcase.
[Bug fortran/117070] Procedure target error with parameter structure constructor
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117070 --- Comment #8 from GCC Commits --- The master branch has been updated by Harald Anlauf : https://gcc.gnu.org/g:4fa9ce0b7d1ac1e495a2ec7a6934ef1be5b74cbb commit r16-5274-g4fa9ce0b7d1ac1e495a2ec7a6934ef1be5b74cbb Author: Harald Anlauf Date: Thu Nov 13 22:34:03 2025 +0100 Fortran: procedure targets in derived-type constructors [PR117070] PR fortran/117070 gcc/fortran/ChangeLog: * array.cc (check_constructor): Allow procedures as potential target of a procedure pointer. gcc/testsuite/ChangeLog: * gfortran.dg/proc_target_1.f90: New test.
[Bug fortran/117070] Procedure target error with parameter structure constructor
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117070 anlauf at gcc dot gnu.org changed: What|Removed |Added Assignee|unassigned at gcc dot gnu.org |anlauf at gcc dot gnu.org Status|WAITING |ASSIGNED --- Comment #7 from anlauf at gcc dot gnu.org --- Submitted: https://gcc.gnu.org/pipermail/fortran/2025-November/063157.html
[Bug fortran/117070] Procedure target error with parameter structure constructor
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117070
--- Comment #6 from anlauf at gcc dot gnu.org ---
This change allows the reduced test from comment#5 to compile:
diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc
index 8f0004992e8..32624d8439e 100644
--- a/gcc/fortran/array.cc
+++ b/gcc/fortran/array.cc
@@ -1644,6 +1644,12 @@ check_constructor (gfc_constructor_base ctor, bool
(*check_function) (gfc_expr *
if (!e)
continue;
+ /* Allow procedures which can be the target of a procedure pointer. */
+ if (e->expr_type == EXPR_VARIABLE
+ && e->ts.type == BT_PROCEDURE
+ && e->symtree->n.sym->attr.flavor == FL_PROCEDURE)
+ continue;
+
if (e->expr_type != EXPR_ARRAY)
{
if (!(*check_function)(e))
This also accepts major parts of the original testcase from comment#0,
but mishandles the part using the static dispatch table.
FTR: this change regtests OK.
[Bug fortran/117070] Procedure target error with parameter structure constructor
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117070 --- Comment #5 from anlauf at gcc dot gnu.org --- (In reply to Ivan Pribec from comment #4) > Steve reckons the example is valid, see: > https://community.intel.com/t5/Intel-Fortran-Compiler/Procedure-target-in- > structure-constructor/m-p/1681101#M175473 While I still have my doubts on the use of the constructor with a named constant, I agree that the following reduced code should compile: module funcs implicit none abstract interface function retchar() character(len=1) :: retchar end function retchar end interface contains function a() character(len=1) :: a a = 'a' end function end module module dispatch_table use funcs implicit none ! Procedure container type :: pc procedure(retchar), pointer, nopass :: rc => null() end type pc type(pc) :: myfun = pc(rc=a) end module Indeed, "7.5.10 Construction of derived‐type values" has: ! For a pointer component, the corresponding component‐data‐source shall be ! an allowable data‐target or proc‐target for such a pointer in a pointer ! assignment statement (10.2.2). If the component data source is a pointer, ! the association of the component is that of the pointer; otherwise, the ! component is pointer associated with the component data source. But the above is rejected with: pr117070-1.f90:25:28: 25 | type(pc) :: myfun = pc(rc=a) |1 Error: Parameter 'a' at (1) has not been declared or is a variable, which does not reduce to a constant expression Intel ifx 2025.3 gives a similar error.
[Bug fortran/117070] Procedure target error with parameter structure constructor
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117070 --- Comment #4 from Ivan Pribec --- Steve reckons the example is valid, see: https://community.intel.com/t5/Intel-Fortran-Compiler/Procedure-target-in-structure-constructor/m-p/1681101#M175473
[Bug fortran/117070] Procedure target error with parameter structure constructor
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117070 --- Comment #3 from Ivan Pribec --- According to my reading, the right hand side in the assignment matches the following two cases of constant expressions, quoting 10.1.12: 2) an array constructor where each element ... is a constant expression 3) a structure constructor where each component-spec corresponding to (b) a pointer component is an initialization target In flang they implement this, with the caveat, the initialization targets in the structure constructor must have an explicit interface "visible" prior to the statement containing the constant expression. Details here: https://github.com/llvm/llvm-project/issues/72058 In general an internal procedure or module procedure has an explicit interface within the scope of the procedure/module, which allows things like this: program test procedure(tp), pointer :: p p => tp print *, p() contains function tp() real :: tp tp = 3.0 end function end program What this means is that in-principle a, b, c could also be declared in the module dispatch_table; the NAG compiler allows this. I can ask on the Intel Community Forum.
[Bug fortran/117070] Procedure target error with parameter structure constructor
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117070 anlauf at gcc dot gnu.org changed: What|Removed |Added Ever confirmed|0 |1 Last reconfirmed||2025-03-18 CC||anlauf at gcc dot gnu.org Priority|P3 |P4 Status|UNCONFIRMED |WAITING --- Comment #2 from anlauf at gcc dot gnu.org --- (In reply to Ivan Pribec from comment #1) > This is supposed to work already with the F2008 standard: > > > nagfor -f2008 dispatch_test.f90 > NAG Fortran Compiler Release 7.2(Shin-Urayasu) Build 7203 > Evaluation trial version of NAG Fortran Compiler Release 7.2(Shin-Urayasu) > Build 7203 > [NAG Fortran Compiler normal termination] > > ./a.out > PASS Hmmm. type(pc), parameter :: table(3) = [pc(a),pc(b),pc(c)] ! Doesn't work We need to understand if this is legal. 8.5.13 PARAMETER attribute "The PARAMETER attribute specifies that an entity is a named constant. The entity has the value specified by its constant-expr, ..." C1012 (R1030) constant-expr shall be a constant expression. 10.1.12 Constant expression "A constant expression is an expression with limitations that make it suitable for use as a kind type parameter, initializer, or named constant. It is an expression in which each operation is intrinsic, and each primary is" ... (7) a reference to an elemental standard intrinsic function, ... (8) a reference to a standard intrinsic function that is transformational, ... (9) a reference to the intrinsic function NULL ... (10) a reference to the intrinsic function TRANSFER ... (11) a reference to a transformational function from the intrinsic module ... ... I do not see any mentioning of a user-defined function being mentioned in this list, so it might be that NAG should not accept the code. Intel also rejects the code. Can you ask Steve Lionel at the Intel forum what he thinks?
[Bug fortran/117070] Procedure target error with parameter structure constructor
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117070 --- Comment #1 from Ivan Pribec --- This is supposed to work already with the F2008 standard: > nagfor -f2008 dispatch_test.f90 NAG Fortran Compiler Release 7.2(Shin-Urayasu) Build 7203 Evaluation trial version of NAG Fortran Compiler Release 7.2(Shin-Urayasu) Build 7203 [NAG Fortran Compiler normal termination] > ./a.out PASS
