[Patch, Fortran] PR25071 - give an error if character len of actual argument too short

Brooks Moses brooks.moses@codesourcery.com
Thu May 3 21:45:00 GMT 2007


Tobias Burnus wrote:
> :ADDPATCH fortran:

:REVIEWMAIL:

> Ok for the trunk?

Ok with a couple of small changes in the testcases:

> Index: gcc/testsuite/gfortran.dg/char_length_3.f90
> ===================================================================
> --- gcc/testsuite/gfortran.dg/char_length_3.f90	(revision 0)
> +++ gcc/testsuite/gfortran.dg/char_length_3.f90	(revision 0)
> @@ -0,0 +1,30 @@
> +! { dg-do compile }
> +! PR fortran/25071
> +! Check if actual argument is too short
> +!
> +        program test
> +           character(len=10) :: x
> +           character(len=30), target :: y
> +           character(len=30), pointer :: ptr
> +           character(len=30), allocatable :: alloc(:)
> +           ptr => y
> +           call foo(x) ! { dg-error "actual argument shorter than of dummy" }
> +           call foo(y)
> +           call foo(ptr)
> +           call bar(ptr) ! { dg-error "Character length mismatch" }
> +           allocate(alloc(1))
> +           call arr(alloc) ! { dg-error "Character length mismatch" }

I think you should also check for the "actual argument shorter" error 
for the pointer and allocatable cases.


> Index: gcc/testsuite/gfortran.dg/char_result_2.f90
> ===================================================================
> --- gcc/testsuite/gfortran.dg/char_result_2.f90	(revision 124381)
> +++ gcc/testsuite/gfortran.dg/char_result_2.f90	(working copy)
[...]
> @@ -53,7 +55,7 @@ program main
>    call test (f5 (textp), 140)
>    call test (f6 (textp), 29)
>  
> -  call indirect (textp)
> +  ! call indirect (textp2) ! needs fixed PR31803
>  contains
>    function f3 (string)
>      integer, parameter :: l1 = 30

I don't think that commenting things out like this is useful -- it's all 
too easy to forget to uncomment them when the PR is fixed.

Instead, leave it as it is, and then whoever fixes the PR can commit a 
testcase for this version of things.  Or make a PR that records the fact 
that this should be changed, and set it to depend on PR31803, or 
something like that.  (Or just make a note in PR31803 about it.)

> @@ -93,7 +95,7 @@ contains
>      call test (f1 (textp2), 50)
>      call test (f2 (textp2, textp), 65)
>      call test (f3 (textp2), 85)
> -    call test (f4 (textp2), 192)
> +!    call test (f4 (textp2), 192) ! invalid: actual leng 50 < formal len 70
>      call test (f5 (textp2), 100)
>      call test (f6 (textp2), 9)
>    end subroutine indirect

If the check is invalid, it should be deleted entirely rather than just 
commented out.

- Brooks



More information about the Fortran mailing list