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

            Bug ID: 104972
           Summary: Class dummy argument for array of custom types stuck
                    on -fcheck=bounds
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: albandil at atlas dot cz
  Target Milestone: ---

When the following program is compiled with `-fcheck=bounds` using a recent
version of gfortran, it triggers a bogus (?) error:

    program test

        type vec
            integer :: x(3)
        end type

        type(vec) :: v(2)

        call sub(v)

    contains

        subroutine sub (v)

            class(vec), intent(in) :: v(:)

            integer :: k, q(3)

            q = [ (v(1)%x(k), k = 1, 3) ]   ! <-- fails here

       end subroutine

    end program

The error message is

    At line 19 of file test.f90
    Fortran runtime error: Index '3' of dimension 1 of array 'v%_data%x' above
upper bound of 2

When the lengths of the arrays `x` and `v` in the code are modified, the
message changes as well, but it always appears as if the compiler interchanged
the dimension of `v` and of `x`. I observe this behaviour with the compiler
version on openSUSE Tumbleweeed 20220316

    $ gfortran --version
    GNU Fortran (SUSE Linux) 11.2.1 20220103 [revision
d4a1d3c4b377f1d4acb34fe1b55b5088a3f293f6]

I also got the same run-time errors when pulling and compiling a recent Git
version of GCC,

    $ gfortran --version
    GNU Fortran (GCC) 12.0.1 20220310 (experimental)

However, in older versions of the compiler (8, 9 and 10) using the
`-fcheck=bounds` flag with this program works fine. Provided that the code is
syntactically valid as it is, this suggests a compiler regression.

The error goes away also when I replace the keyword `class` with `type`.

Reply via email to