[Bug fortran/91782] New: Accepts invalid array constructor with character parameter

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug fortran/91782] New: Accepts invalid array constructor with character parameter

rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91782

            Bug ID: 91782
           Summary: Accepts invalid array constructor with character
                    parameter
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: [hidden email]
  Target Milestone: ---

A parameter attribute prevents some checks in comparison to a
character variable. Affects gfortran down to at least version 5.


$ cat z1.f90
program p
   integer :: i
   character(3), parameter :: x = 'abc'
   print *, ['abc'(1:1), 'abc'(1:2), 'abc'(1:3)]
   print *, [x(1:1), x(1:2), x(1:3)]
   print *, [(x(1:i), i=1,3)]
   print *, ichar(([(x(1:i), i=1,3)]))
   print *, len_trim([(x(min(1,i):i), i=1,3)])
end


$ gfortran-10-20190915 z1.f90 && ./a.out
 aaa
 aaa
 aaa
          97          97          97
           1           1           1
Reply | Threaded
Open this post in threaded view
|

[Bug fortran/91782] Accepts invalid array constructor with character parameter

rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91782

G. Steinmetz <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid

--- Comment #1 from G. Steinmetz <[hidden email]> ---

$ cat z2.f90      # without parameter
program p
   integer :: i
   character(3) :: x = 'abc'
   print *, ['a', 'ab', 'abc']
   print *, [x(1:1), x(1:2), x(1:3)]
   print *, [(x(1:i), i=1,3)]
   print *, ichar(([(x(1:i), i=1,3)]))
   print *, len_trim([(x(min(1,i):i), i=1,3)])
end


$ gfortran-10-20190915 -c z2.f90
z2.f90:4:17:

    4 |    print *, ['a', 'ab', 'abc']
      |                 1
Error: Different CHARACTER lengths (1/2) in array constructor at (1)
z2.f90:5:20:

    5 |    print *, [x(1:1), x(1:2), x(1:3)]
      |                    1
Error: Different CHARACTER lengths (1/2) in array constructor at (1)
z2.f90:6:14:

    6 |    print *, [(x(1:i), i=1,3)]
      |              1
Error: Different CHARACTER lengths (1/2) in array constructor at (1)
z2.f90:7:21:

    7 |    print *, ichar(([(x(1:i), i=1,3)]))
      |                     1
Error: Different CHARACTER lengths (1/2) in array constructor at (1)
z2.f90:8:23:

    8 |    print *, len_trim([(x(min(1,i):i), i=1,3)])
      |                       1
Error: Different CHARACTER lengths (1/2) in array constructor at (1)