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

--- Comment #12 from Harald Anlauf <anlauf at gcc dot gnu.org> ---
(In reply to Ivan Pribec from comment #11)
> 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

Thanks for the update.

Indeed this works.  I might add the following to the committed testcase:

  block
    use dispatch_table, only: table => dtab_p   ! Static table
    character(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 14
  end block

However, I found some other tests that ICE (also with ASSOCIATE), like:

  block
!   use dispatch_table, only: table => dtab_v   ! Dynamic table, works
    use dispatch_table, only: table => dtab_p   ! Static table,  ICE below
    character(3) :: abc
    integer      :: i
    do i = 1, 3
       abc(i:i) =  table(i)%rc()    ! ICE in gfc_trans_assignment_1
!      abc(i:i) = (table(i)%rc())   ! ICE in gfc_trans_assignment_1
    end do
    if (abc /= 'abc') stop 15
  end block

I think this should be valid, and it is accepted by NAG and aof.

Reply via email to