diff mbox

[Fortran,OOP] PR 49638: [OOP] length parameter is ignored when overriding type bound character functions with constant length.

Message ID CAKwh3qix=_eOxtY1r3nLJbuiGEtbEg9CMuGvqfKPVCco+U39Xg@mail.gmail.com
State New
Headers show

Commit Message

Janus Weil Aug. 7, 2011, 10:56 a.m. UTC
>> OK from my side (given Mikael's comments), provided you spell resolve.c with
>> two e :-)
>
> Thanks, guys. Committed as r177545 (including your comments).


Ok, with the 'trivial' parts out of the way, the remainder of my
previously proposed patch becomes rather compact (see attachment).

Thomas' ongoing criticism is that rejecting all nonzero return values
of 'gfc_dep_compare_expr' will reject too much (i.e. cases where we
can not prove that the expressions are equal, but they may still be).

My feeling is that only throwing a warning for a result of '-2' is too
weak, because the majority of cases will have that result (just think
'len=3' vs. 'len=n').

Instead I could offer to try to extend the return values of
'gfc_dep_compare_expr' to distinguish between the following cases
(which right now would both result in '-2'):

a) We can not determine the relationship between both expressions, but
we know they are different for certain input values. (This case would
include e.g. different expr_type)

b) We cannot make any statement.

Is this the way to go? Or are there any other proposals for resolving
this argument?

Cheers,
Janus

Comments

Thomas Koenig Aug. 7, 2011, 11:59 a.m. UTC | #1
Am 07.08.2011 12:56, schrieb Janus Weil:
> +      /* Check string length.  */
> +      if (proc_target->result->ts.type == BT_CHARACTER
> +	&&  proc_target->result->ts.u.cl&&  old_target->result->ts.u.cl
> +	&&  gfc_dep_compare_expr (proc_target->result->ts.u.cl->length,
> +				   old_target->result->ts.u.cl->length) != 0)
> +	{
> +	  gfc_error ("Character length mismatch between '%s' at '%L' "
> +		     "and overridden FUNCTION", proc->name,&where);
> +	  return FAILURE;
> +	}
>       }

Well, let's make this into (again, typing the patch directly into
e-mail)

	
       /* Check string length.  */
       if (proc_target->result->ts.type == BT_CHARACTER
	  && proc_target->result->ts.u.cl && old_target->result->ts.u.cl
             {
                int compval =
	  gfc_dep_compare_expr (proc_target->result->ts.u.cl->length,
				   old_target->result->ts.u.cl->length);

              switch (compval)
	{
	    case -3:
             case -1:
             case 1:

	  gfc_error ("Character length mismatch between '%s' at '%L' "
		     "and overridden FUNCTION", proc->name, &where);
	  return FAILURE;

	    case -2:
            gfc_warning ("Possible length mismatch between '%s' at '%L' "
                         "and overriden FUNCTION, proc->name, &where);
            break;

	case 0:
	    break;

	default:
	    gfc_internal_error ("Unexpected return of gfc_dep_compare_expr";
            break;
        }

and then work on extending gfc_dep_compare_expr to return -3 for more 
cases.  I can help with that.

Regards

	Thomas
diff mbox

Patch

Index: gcc/fortran/interface.c
===================================================================
--- gcc/fortran/interface.c	(revision 177545)
+++ gcc/fortran/interface.c	(working copy)
@@ -3556,15 +3556,25 @@  gfc_check_typebound_override (gfc_symtree* proc, g
 	}
 
       /* FIXME:  Do more comprehensive checking (including, for instance, the
-	 rank and array-shape).  */
+	 array-shape).  */
       gcc_assert (proc_target->result && old_target->result);
-      if (!gfc_compare_types (&proc_target->result->ts,
-			      &old_target->result->ts))
+      if (!compare_type_rank (proc_target->result, old_target->result))
 	{
 	  gfc_error ("'%s' at %L and the overridden FUNCTION should have"
-		     " matching result types", proc->name, &where);
+		     " matching result types and ranks", proc->name, &where);
 	  return FAILURE;
 	}
+	
+      /* Check string length.  */
+      if (proc_target->result->ts.type == BT_CHARACTER
+	  && proc_target->result->ts.u.cl && old_target->result->ts.u.cl
+	  && gfc_dep_compare_expr (proc_target->result->ts.u.cl->length,
+				   old_target->result->ts.u.cl->length) != 0)
+	{
+	  gfc_error ("Character length mismatch between '%s' at '%L' "
+		     "and overridden FUNCTION", proc->name, &where);
+	  return FAILURE;
+	}
     }
 
   /* If the overridden binding is PUBLIC, the overriding one must not be
Index: gcc/fortran/dependency.c
===================================================================
--- gcc/fortran/dependency.c	(revision 177545)
+++ gcc/fortran/dependency.c	(working copy)
@@ -123,8 +123,18 @@  are_identical_variables (gfc_expr *e1, gfc_expr *e
 {
   gfc_ref *r1, *r2;
 
-  if (e1->symtree->n.sym != e2->symtree->n.sym)
-    return false;
+  if (e1->symtree->n.sym->attr.dummy && e2->symtree->n.sym->attr.dummy)
+    {
+      /* Dummy arguments: Only check for equal names.  */
+      if (e1->symtree->n.sym->name != e2->symtree->n.sym->name)
+	return false;
+    }
+  else
+    {
+      /* Check for equal symbols.  */
+      if (e1->symtree->n.sym != e2->symtree->n.sym)
+	return false;
+    }
 
   /* Volatile variables should never compare equal to themselves.  */