Re: [PATCH] Fortran: fix string length for array constructors with type-spec [PR85547]

Harald Anlauf <[email protected]>
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <[email protected]>
Am 05.01.26 um 10:06 PM schrieb Jerry D:
> On 1/5/26 12:32 PM, Harald Anlauf wrote:
>> Dear All,
>>
>> when a type-spec was provided with a character array constructor,
>> it seemed to get "lost" when passing the array constructor to
>> a procedure, even to the LEN() intrinsic.
>>
>> The attached patch fixes this, enables simplification of LEN()
>> when passed an array constructor with type-spec, and also adds
>> the type-spec to the fortran dump.
>>
>> Regtested on x86_64-pc-linux-gnu.  OK for mainline?
>>
>> Thanks,
>> Harald
>>
> 
> Hi Harald,
> 
> I just finished testing this. Looks OK to go.
> 
> I did not see anything obviously wrong with this.
> 
> Commit at your discretion.
> 
> Jerry

Hi Jerry,

thanks for checking.  Unfortunately, I found a last-minute issue...

The following code was previously miscompiled and is now rejected:

program p
   integer :: n = 2
   call foo ([character(n) :: 'abc'])
contains
   subroutine foo (x)
     character(*), intent(in) :: x(:)
     print *, len(x)
   end subroutine foo
end

gcc-15 prints 3 instead of 2; gcc-16 with my patch does:

pr47425-xx.f90:3:36:

     3 |   call foo ([character(n) :: 'abc'])
       |                                    ^
Error: size of variable 'A.5' is too large

This is triggered by the hunk from trans-array.cc.
I have to think a little bit longer how to proceed...
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.