re PR fortran/77358 ([F08] deferred-length character function returns zero-length...
authorPaul Thomas <pault@gcc.gnu.org>
Wed, 24 Aug 2016 19:33:14 +0000 (19:33 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Wed, 24 Aug 2016 19:33:14 +0000 (19:33 +0000)
2016-08-24  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/77358
* resolve.c (resolve_fl_procedure): Use the correct gfc_charlen
for deferred character length module procedures.

2016-08-24  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/77358
* gfortran.dg/submodule_17.f08: New test.

From-SVN: r239740

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/submodule_17.f08 [new file with mode: 0644]

index 6dc44e6f035801c7b04e09dc5846ade0868aecf5..93eb48ad52bc1fe1bafe66e140f067ba40aba21f 100644 (file)
@@ -1,3 +1,9 @@
+2016-08-24  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/77358
+       * resolve.c (resolve_fl_procedure): Use the correct gfc_charlen
+       for deferred character length module procedures.
+
 2016-08-23  Fritz Reese  <fritzoreese@gmail.com>
 
        * decl.c (gfc_match_structure_decl): Make gfc_structure_id static.
index b7036a82837a328d01a9230d967044383a312adb..0a92efe7784fe8103bf958310ab045f3a2cafe3d 100644 (file)
@@ -11884,6 +11884,13 @@ resolve_fl_procedure (gfc_symbol *sym, int mp_flag)
       iface = sym->ts.interface;
       sym->ts.interface = NULL;
 
+      /* Make sure that the result uses the correct charlen for deferred
+        length results.  */
+      if (iface && sym->result
+         && iface->ts.type == BT_CHARACTER
+         && iface->ts.deferred)
+       sym->result->ts.u.cl = iface->ts.u.cl;
+
       if (iface == NULL)
        goto check_formal;
 
index 2393eb5ce570f7e1575424147ba23211ec2974be..527f2011ac7569daa906b4396d3564242e4783d6 100644 (file)
@@ -1,3 +1,8 @@
+2016-08-24  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/77358
+       * gfortran.dg/submodule_17.f08: New test.
+
 2016-08-24  Michael Collison <michael.collison@linaro.org>
            Michael Collison <michael.collison@arm.com>
 
diff --git a/gcc/testsuite/gfortran.dg/submodule_17.f08 b/gcc/testsuite/gfortran.dg/submodule_17.f08
new file mode 100644 (file)
index 0000000..8effef4
--- /dev/null
@@ -0,0 +1,27 @@
+! { dg-do run }
+!
+! Tests the fix for PR77358, in which the wrong gfc_charlen was
+! being used for the result of 'get'.
+!
+! Contributed by Damian Rouson  <damian@sourceryinstitute.org>
+!
+module hello_interface
+  character(len=13) :: string="Hello, world!"
+  interface
+    module function get() result(result_string)
+      character(:), allocatable :: result_string
+    end function
+  end interface
+end module
+
+submodule(hello_interface) hello_implementation
+contains
+  module function get() result(result_string)
+    character(:), allocatable :: result_string
+    result_string = string
+  end function
+end submodule
+
+  use hello_interface
+  if (get() .ne. string) call abort
+end