This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/33759] New: Unequal character lengths in MERGE intrinsic not detected in contained function.


In my comment 31 of PR31608, I have questionned the validity of the test case
in comment 28.  Now I think the test is invalid, but not detected. First
consider the code:

character(len=20) :: string
character(len=1)  :: tmp(20)
string = ""
tmp = ""
tmp = transfer(string,"x",len(string))
tmp = merge(tmp, string, .true.)
end

gfortran gives:

tmp = merge(tmp, string, .true.)
           1
Error: Unequal character lengths (1 and 20) in MERGE intrinsic at (1)

Note that an error based on the shape would probably better. When using arrays
of real, I get:

Error: Different shape for arguments 'tsource' and 'fsource' for intrinsic
'merge' at (1) on dimension 1 (3 and 2)

Now consider the code

  character(len=1)  :: string = "z"
  character(len=20) :: tmp = ""
  tmp = Upper ("abcdefg")
  print *, "'", tmp, "'"
 contains
  Character (len=20) Function Upper (string)
    Character(len=*) string
    character(len=1) :: tmp(20) = ""
    tmp = transfer(string,"x",len(string))
    tmp = merge(tmp, string, .true.)
    Upper = transfer(tmp, "x")
    return
  end function Upper
end

gfortran compiles it without complain and gives

 'a                   '

I think the above code is invalid in two counts:

(1) transfer(string,"x",len(string)) is a rank one array of size 7 and should
not be assigned to an array of size 20.  I think this is quite difficult to
detect at compile time, but it would be nice to have it at runtime.

(2) merge(tmp, string, .true.) try to merge a rank one character array with a
rank zero string. If this invalid and detected in the first test above, it
should also be detected in the function, unless I am missing something.


-- 
           Summary: Unequal character lengths in MERGE intrinsic not
                    detected in contained function.
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dominiq at lps dot ens dot fr
 GCC build triplet: powerpc-apple-darwin8
  GCC host triplet: powerpc-apple-darwin8
GCC target triplet: powerpc-apple-darwin8


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33759


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]