Bug 55901

Summary: [OOP] type is (character(len=*)) misinterpreted as array
Product: gcc Reporter: Harald Anlauf <anlauf>
Component: fortranAssignee: Andre Vehreschild <vehre>
Status: RESOLVED FIXED    
Severity: normal CC: burnus, janus, paul.richard.thomas, pault
Priority: P3 Keywords: rejects-valid
Version: 4.8.0   
Target Milestone: 5.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2013-09-18 00:00:00
Attachments: Partial patch for the PR

Description Harald Anlauf 2013-01-07 19:37:26 UTC
Hi,

this small example is IMO wrongly rejected:

module gfcbug123
  implicit none
  type myobj
     class(*), allocatable :: x
   contains
     procedure :: print
  end type myobj
contains
  subroutine print(this)
    class(myobj) :: this
    select type (x => this% x)
    type is (character(len=*))
       print *, "String: ", x(1:len(x))
    end select
  end subroutine print
end module gfcbug123

% gfc-trunk gfcbug123.f90 -c
gfcbug123.f90:12.30:

    type is (character(len=*))
                              1
Error: Associate-name '__tmp_CHARACTER_0_1' at (1) is used as array
Comment 1 pdande1 2013-04-08 17:13:19 UTC
program characterconversions
    integer :: i=123
    character(len=*) :: s
    write(s,*) i
    print *,s
end program

I am getting the below error while executing the above program (gcc version 4.8.0 20130302 (experimental) [trunk revision 196403] (GCC))

Error: Entity with assumed character length  must be a dummy argument or a PARAMETER|
||=== Build finished: 1 errors, 0 warnings (0 minutes, 0 seconds) ===|
Comment 2 Harald Anlauf 2013-04-08 17:29:03 UTC
(In reply to comment #1)
> program characterconversions
>     integer :: i=123
>     character(len=*) :: s
>     write(s,*) i
>     print *,s
> end program
> 
> I am getting the below error while executing the above program (gcc version
> 4.8.0 20130302 (experimental) [trunk revision 196403] (GCC))
> 
> Error: Entity with assumed character length  must be a dummy argument or a
> PARAMETER|
> ||=== Build finished: 1 errors, 0 warnings (0 minutes, 0 seconds) ===|

Your example has nothing to do with the original PR.

It is also invalid code: you must not use assumed character length (i.e. len=*)
in a main program.
Comment 3 pdande1 2013-04-08 17:41:45 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > program characterconversions
> >     integer :: i=123
> >     character(len=*) :: s
> >     write(s,*) i
> >     print *,s
> > end program
> > 
> > I am getting the below error while executing the above program (gcc version
> > 4.8.0 20130302 (experimental) [trunk revision 196403] (GCC))
> > 
> > Error: Entity with assumed character length  must be a dummy argument or a
> > PARAMETER|
> > ||=== Build finished: 1 errors, 0 warnings (0 minutes, 0 seconds) ===|
> 
> Your example has nothing to do with the original PR.
> 
> It is also invalid code: you must not use assumed character length (i.e. len=*)
> in a main program.

Hi Harald,

I am newbie to fortran, Can you please explain me in detail with an example.

Thanks in advance
Comment 4 Harald Anlauf 2013-04-08 18:16:06 UTC
(In reply to comment #3)
> I am newbie to fortran, Can you please explain me in detail with an example.
> 
> Thanks in advance

Replace

    character(len=*) :: s

in your code by e.g.

    character(len=20) :: s

Then it will compile work.  This is a general Fortran issue
and has nothing to do with gfortran.

Note: the bugzilla should not be used to learn about Fortran.
Use a textbook about Fortran or the newsgroup "comp.lang.fortran"
which you can access via google groups.
Comment 5 janus 2013-09-18 11:51:52 UTC
Here is another code which triggers this error:

ftp://ftp.numerical.rl.ac.uk/pub/MRandC/oo.f90

(cf. also https://groups.google.com/forum/?fromgroups#!topic/comp.lang.fortran/aRz3HMpblTs)
Comment 6 Harald Anlauf 2014-12-04 21:13:26 UTC
Any news on this one?
Comment 7 Paul Thomas 2014-12-09 09:02:06 UTC
(In reply to Harald Anlauf from comment #6)
> Any news on this one?

Dear Harald,

I'll take a look at it tonight. Andre is working on a patch that will allow the likes of oo.f90 to work correctly with characters. This bug gets in the way and so I will see what can be done :-) It should be trivial.....

Cheers

Paul
Comment 8 paul.richard.thomas@gmail.com 2014-12-14 21:16:04 UTC
Created attachment 34281 [details]
Partial patch for the PR

This patch removes the error and correctly converts the code, except for the lack of a string length for the unlimited polymorphic entities/components in both the testcase here and oo.f90.

Andre is attending to this but I will in the meantime submit this patch.

Cheers

Paul
Comment 9 paul.richard.thomas@gmail.com 2014-12-14 21:17:55 UTC
By the way, the patch of comment 8 bootstraps and regtests OK

Paul
Comment 10 Harald Anlauf 2015-01-06 19:50:14 UTC
(In reply to paul.richard.thomas@gmail.com from comment #9)
> By the way, the patch of comment 8 bootstraps and regtests OK
> 
> Paul

Hi Paul,

any news on that patch?

Harald
Comment 11 paul.richard.thomas@gmail.com 2015-01-07 13:16:25 UTC
Hi Harald,

Happy New Year! I have been away in Claifornia these last few weeks and
just got back last night.

I am working with Andre on pr60255 tonight. Once this is done, we should be
in a position to fix pr55901 and have it do something useful!

Cheers

Paul

On 6 January 2015 at 20:50, anlauf at gmx dot de <gcc-bugzilla@gcc.gnu.org>
wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55901
>
> --- Comment #10 from Harald Anlauf <anlauf at gmx dot de> ---
> (In reply to paul.richard.thomas@gmail.com from comment #9)
> > By the way, the patch of comment 8 bootstraps and regtests OK
> >
> > Paul
>
> Hi Paul,
>
> any news on that patch?
>
> Harald
>
> --
> You are receiving this mail because:
> You are on the CC list for the bug.
>
Comment 12 Andre Vehreschild 2015-01-07 16:09:42 UTC
Hi Paul, hi Tobias,

I am guilty in asking both of you to look at the issue. I would be very happy,
if one of you two can really have a look into the issue and notify the other
one, that he found a reason for the issue and may be already has a solution. I
just want to get the issue resolved but not produce duplicate work.

Regards,
	Andre


On Wed, 07 Jan 2015 13:16:25 +0000
"paul.richard.thomas at gmail dot com" <gcc-bugzilla@gcc.gnu.org> wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55901
> 
> --- Comment #11 from paul.richard.thomas at gmail dot com
> <paul.richard.thomas at gmail dot com> --- Hi Harald,
> 
> Happy New Year! I have been away in Claifornia these last few weeks and
> just got back last night.
> 
> I am working with Andre on pr60255 tonight. Once this is done, we should be
> in a position to fix pr55901 and have it do something useful!
> 
> Cheers
> 
> Paul
> 
> On 6 January 2015 at 20:50, anlauf at gmx dot de <gcc-bugzilla@gcc.gnu.org>
> wrote:
> 
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55901
> >
> > --- Comment #10 from Harald Anlauf <anlauf at gmx dot de> ---
> > (In reply to paul.richard.thomas@gmail.com from comment #9)
> > > By the way, the patch of comment 8 bootstraps and regtests OK
> > >
> > > Paul
> >
> > Hi Paul,
> >
> > any news on that patch?
> >
> > Harald
> >
> > --
> > You are receiving this mail because:
> > You are on the CC list for the bug.
> >
>
Comment 13 Paul Thomas 2015-01-18 12:22:11 UTC
Author: pault
Date: Sun Jan 18 12:21:38 2015
New Revision: 219814

URL: https://gcc.gnu.org/viewcvs?rev=219814&root=gcc&view=rev
Log:
2015-01-18  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/55901
	* primary.c (gfc_match_varspec): Exclude dangling associate-
	names with dimension 0 from being counted as arrays.
	* resolve.c (resolve_assoc_var): Sub-strings are permissible
	for associate-names, so exclude characters from the test for
	misuse as arrays.
	* trans-decl.c (gfc_get_symbol_decl): Associate-names can use
	the hidden string length variable of their associated target.
	Signal this by setting 'length' to a constant, if the decl for
	the string length is a variable.

2015-01-18  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/55901
	* gfortran.dg/associate_1.f03: Allow test for character with
	automatic length.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/primary.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/associate_1.f03
Comment 15 Andre Vehreschild 2015-03-24 11:48:17 UTC
Author: vehre
Date: Tue Mar 24 11:47:45 2015
New Revision: 221627

URL: https://gcc.gnu.org/viewcvs?rev=221627&root=gcc&view=rev
Log:
2015-03-24  Andre Vehreschild  <vehre@gmx.de>

	PR fortran/55901
	* trans-expr.c (gfc_conv_structure): Fixed indendation.
	Using integer_zero_node now instead of explicitly
	constructing a integer constant zero node.
	(gfc_conv_derived_to_class): Add handling of _len component,
	i.e., when the rhs has a string_length then assign that to
	class' _len, else assign 0.
	(gfc_conv_intrinsic_to_class): Likewise.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
Comment 16 Andre Vehreschild 2015-03-25 09:18:55 UTC
Fixed with commit r221627.
Comment 17 Dominique d'Humieres 2016-05-03 08:15:15 UTC
*** Bug 60561 has been marked as a duplicate of this bug. ***