re PR fortran/51791 ([OOP] Failure to resolve typebound function call with base objec...
authorPaul Thomas <pault@gcc.gnu.org>
Mon, 9 Jan 2012 20:25:55 +0000 (20:25 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Mon, 9 Jan 2012 20:25:55 +0000 (20:25 +0000)
2012-01-09  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/51791
* interface.c (matching_typebound_op): Drill down through
possible parentheses to obtain base expression. Do not test for
'class_ok' but, instead for the class structure components.
* resolve.c (resolve_ordinary_assign): Extend error message for
polymorphic assignment to advise checking for specific
subroutine.

PR fortran/51792
* resolve.c (resolve_typebound_function): Restore 'static' to
declaration.

2012-01-09  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/51791
* gfortran.dg/typebound_operator_7.f03: Insert parentheses
around base object in first assignment in main program.
* gfortran.dg/typebound_operator_10.f03: New test.

From-SVN: r183032

gcc/fortran/ChangeLog
gcc/fortran/interface.c
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/typebound_operator_10.f03 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/typebound_operator_7.f03

index 755e11ee3355ca167e721b864fb925ff0b0c5860..d4e968e5bc53c7a0e3d9a5d1811f4b51e07502de 100644 (file)
@@ -1,3 +1,17 @@
+2012-01-09  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/51791
+       * interface.c (matching_typebound_op): Drill down through
+       possible parentheses to obtain base expression. Do not test for
+       'class_ok' but, instead for the class structure components.
+       * resolve.c (resolve_ordinary_assign): Extend error message for
+       polymorphic assignment to advise checking for specific
+       subroutine.
+
+       PR fortran/51792
+       * resolve.c (resolve_typebound_function): Restore 'static' to
+       declaration.
+
 2012-01-09  Mikael Morin  <mikael@gcc.gnu.org>
 
        PR fortran/51758
index 773749d5ebcdd96982e7c85f66eea23b0beced9a..94f767d740cc2115165535eab026bd79207626d9 100644 (file)
@@ -3168,9 +3168,13 @@ matching_typebound_op (gfc_expr** tb_base,
        gfc_symbol* derived;
        gfc_try result;
 
+       while (base->expr->expr_type == EXPR_OP
+              && base->expr->value.op.op == INTRINSIC_PARENTHESES)
+         base->expr = base->expr->value.op.op1;
+
        if (base->expr->ts.type == BT_CLASS)
          {
-           if (!gfc_expr_attr (base->expr).class_ok)
+           if (CLASS_DATA (base->expr) == NULL)
              continue;
            derived = CLASS_DATA (base->expr)->ts.u.derived;
          }
index 79245ce89bf94be728dc8b7178012f6aa27858ed..c48e2b19e658c448803d30626cbd710e1cf24c71 100644 (file)
@@ -5887,7 +5887,7 @@ resolve_compcall (gfc_expr* e, const char **name)
 /* Resolve a typebound function, or 'method'. First separate all
    the non-CLASS references by calling resolve_compcall directly.  */
 
-gfc_try
+static gfc_try
 resolve_typebound_function (gfc_expr* e)
 {
   gfc_symbol *declared;
@@ -9208,8 +9208,9 @@ resolve_ordinary_assign (gfc_code *code, gfc_namespace *ns)
      and coindexed; cf. F2008, 7.2.1.2 and PR 43366.  */
   if (lhs->ts.type == BT_CLASS)
     {
-      gfc_error ("Variable must not be polymorphic in assignment at %L",
-                &lhs->where);
+      gfc_error ("Variable must not be polymorphic in assignment at %L "
+                "- check that there is a matching specific subroutine "
+                "for '=' operator", &lhs->where);
       return false;
     }
 
index 8b2f465665cd8c7ebc48e9c16c93c4c482fffd5f..32fcb4953efdae42ddf7350f6bc1ee6a3bb03ff4 100644 (file)
@@ -1,3 +1,10 @@
+2012-01-09  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/51791
+       * gfortran.dg/typebound_operator_7.f03: Insert parentheses
+       around base object in first assignment in main program.
+       * gfortran.dg/typebound_operator_10.f03: New test.
+
 2012-01-09  Martin Jambor  <mjambor@suse.cz>
 
         PR tree-optimization/51759
diff --git a/gcc/testsuite/gfortran.dg/typebound_operator_10.f03 b/gcc/testsuite/gfortran.dg/typebound_operator_10.f03
new file mode 100644 (file)
index 0000000..146eab0
--- /dev/null
@@ -0,0 +1,29 @@
+! { dg-do compile }
+! PR51791 and original testcase for PR46328.
+!
+! Contributer by Thomas Koenig  <tkoenig@gcc.gnu.org>
+!
+module field_module
+  implicit none
+  type ,abstract :: field
+  contains
+    procedure(field_op_real) ,deferred :: multiply_real
+    generic :: operator(*) => multiply_real
+  end type
+  abstract interface
+    function field_op_real(lhs,rhs)
+      import :: field
+      class(field) ,intent(in)  :: lhs
+      real ,intent(in) :: rhs
+      class(field) ,allocatable :: field_op_real
+    end function
+  end interface
+end module
+
+program main
+  use field_module
+  implicit none
+  class(field) ,pointer :: u
+  u = (u)*2. ! { dg-error "check that there is a matching specific" }
+end program
+! { dg-final { cleanup-modules "field_module" } }
index c61a00c6671c3ae07a54b0ae594b8e03d001f873..a7b0f81722af5448aa7564446e8d1f1032641ba8 100644 (file)
@@ -90,7 +90,7 @@ program main
   class(i_field) ,allocatable :: u
   allocate (u, source = i_field (99))
 
-  u = u*2.
+  u = (u)*2.
   u = (u*2.0*4.0) + u*4.0
   u = u%multiply_real (2.0)*4.0
   u = i_multiply_real (u, 2.0) * 4.0