https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117070

--- Comment #11 from Ivan Pribec <ivan.pribec at gmail dot com> ---
Upon further reading of the standard, two more rules that look relevant here:

On (scalar) variables:

  C901 (R902) designator shall not be a constant or a subobject of a constant.

On procedure pointers:

  R1040 proc-component-ref is scalar-variable % procedure-component-name

So in the original example, the expression 

  table(1)%rc()//table(2)%rc()//table(3)%rc()

is calling through named constants instead of variables, which is incorrect. My
apologies.

So the static dispatch example must be modified to use either a temporary
variable or an associate:

    block
        use dispatch_table, only: table ! Static table
        character(len=3) :: abc
        integer :: i
        do i = 1, 3
            associate(t => table(i))
                abc(i:i) = t%rc()
            end associate
        end do
        if (abc /= 'abc') stop 2
    end block

With this change, GCC 16.2 works:

$ gfortran dispatch_test.f90 && ./a.out
 PASS
$ flang dispatch_test.f90 && ./a.out
 PASS

Reply via email to