]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/68544 (ICE trying to pass derived type constructor as a function)
authorSteven G. Kargl <kargl@gcc.gnu.org>
Thu, 13 Jun 2019 18:40:19 +0000 (18:40 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Thu, 13 Jun 2019 18:40:19 +0000 (18:40 +0000)
2019-06-13  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/68544
* resolve.c (is_dt_name): New function to compare symbol name against
list of derived types.
(resolve_actual_arglist): Use it to find wrong code.

2019-06-13  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/68544
* gfortran.dg/pr68544.f90: New test.
* gfortran.dg/pr85687.f90: Modify test for new error message.

From-SVN: r272259

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr68544.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/pr85687.f90

index 2b2395c68c14478ad266e9a2493c46f85df7c590..99a399abc719e46012974a0422a1fd467520b6a8 100644 (file)
@@ -1,3 +1,10 @@
+2019-06-12  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/68544
+       * resolve.c (is_dt_name): New function to compare symbol name against
+       list of derived types.
+       (resolve_actual_arglist): Use it to find wrong code.
+
 2019-06-13  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/89344
index 8232deb81704b8cea92e1a6064870b7cbc801046..c565325ee2f4db129fd9d8d72548e82d6360b767 100644 (file)
@@ -1862,6 +1862,25 @@ resolve_procedure_expression (gfc_expr* expr)
 }
 
 
+/* Check that name is not a derived type.  */
+static bool
+is_dt_name (const char *name)
+{
+  gfc_symbol *dt_list, *dt_first;
+
+  dt_list = dt_first = gfc_derived_types;
+  for (; dt_list; dt_list = dt_list->dt_next)
+    {
+      if (strcmp(dt_list->name, name) == 0)
+       return true;
+      if (dt_first == dt_list->dt_next)
+       break;
+    }
+  return false;
+}
+
+
 /* Resolve an actual argument list.  Most of the time, this is just
    resolving the expressions in the list.
    The exception is that we sometimes have to decide whether arguments
@@ -1923,6 +1942,13 @@ resolve_actual_arglist (gfc_actual_arglist *arg, procedure_type ptype,
 
       sym = e->symtree->n.sym;
 
+      if (sym->attr.flavor == FL_PROCEDURE && is_dt_name (sym->name))
+       {
+         gfc_error ("Derived type %qs is used as an actual "
+                    "argument at %L", sym->name, &e->where);
+         goto cleanup;
+       }
+
       if (sym->attr.flavor == FL_PROCEDURE
          || sym->attr.intrinsic
          || sym->attr.external)
index 759209468c1f4d5e6a50fb7640572fb52748aabd..c5c68eac373bc9362e767da6d69c1b43190c9c6c 100644 (file)
@@ -1,3 +1,9 @@
+2019-06-13  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/68544
+       * gfortran.dg/pr68544.f90: New test.
+       * gfortran.dg/pr85687.f90: Modify test for new error message.
+
 2019-06-13  Iain Sandoe  <iain@sandoe.co.uk>
 
        * g++.dg/pr71694.C: Use non-PIC codegen for Darwin m32.
diff --git a/gcc/testsuite/gfortran.dg/pr68544.f90 b/gcc/testsuite/gfortran.dg/pr68544.f90
new file mode 100644 (file)
index 0000000..3b17e2a
--- /dev/null
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! PF fortran/68544
+program p
+   real x
+   type t
+   end type
+   x = f(t)             ! { dg-error "used as an actual argument" }
+end
+subroutine b
+   type t
+   end type
+   print *, shape(t)    ! { dg-error "used as an actual argument" }
+end
index 03bc2119364c65a0c99792cd4ccc9f0fb3bf6e9c..410b2b2a5cc27e6a1c950f696e7fe1c1833fabe2 100644 (file)
@@ -4,5 +4,5 @@
 program p
    type t
    end type
-   print *, rank(t)  ! { dg-error "must be a data object" }
+   print *, rank(t)  ! { dg-error "used as an actual argument" }
 end