See 31610 for another example.

"13.7.75 MERGE (TSOURCE, FSOURCE, MASK)"
"FSOURCE shall be of the same type and type parameters as TSOURCE."

NAG f95:
Error: merge_char_3.f90, line 4: Unequal character lengths (2 and 3) in MERGE
intrinsic
Error: merge_char_3.f90, line 5: Unequal character lengths (2 and 3) in MERGE
intrinsic


implicit none
character(len=2) :: a
character(len=3) :: b
print *, merge(a,b,.true.)  ! { dg-error "Unequal character lengths" }
print *, merge('aa','bbb',.true.)  ! { dg-error "Unequal character lengths" }
end


First version of a patch follows. However, it does not detect the second
transfer as for 'aa' expr->ts.cl->length etc. is not set, but only
expr->value.character.length (cf. match_string_constant). (Note: setting cl.*
in 
match_string_constant does not completely work: In
gfortran.dg/char_length_1.f90 the warning for line 12 and 14 is then
suppressed.)

Index: check.c
===================================================================
--- check.c     (Revision 128550)
+++ check.c     (Arbeitskopie)
@@ -1820,6 +1820,23 @@
   if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
     return FAILURE;

+  /* In case of characters, the string lengths need to match.  */
+  if (tsource->ts.type == BT_CHARACTER && tsource->ts.cl
+      && tsource->ts.cl->length && fsource->ts.cl && fsource->ts.cl->length
+      && tsource->ts.cl->length->expr_type == EXPR_CONSTANT
+      && fsource->ts.cl->length->expr_type == EXPR_CONSTANT
+      && mpz_cmp (tsource->ts.cl->length->value.integer,
+                 fsource->ts.cl->length->value.integer) != 0)
+    {
+      gfc_error ("Unequal character lengths (%ld and %ld) in MERGE "
+                "intrinsic at %L",
+                mpz_get_si (tsource->ts.cl->length->value.integer),
+                mpz_get_si (fsource->ts.cl->length->value.integer),
+                &tsource->where);
+      return FAILURE;
+    }
+
+
   if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
     return FAILURE;



In case some one is interested in the match_string_constant change (which
causes the warn regression), here it comes:

Index: primary.c
===================================================================
--- primary.c   (Revision 128550)
+++ primary.c   (Arbeitskopie)
@@ -946,6 +946,8 @@ got_delim:

   e->value.character.string = p = gfc_getmem (length + 1);
   e->value.character.length = length;
+  e->ts.cl = gfc_get_charlen ();
+  e->ts.cl->length = gfc_int_expr (length);

   gfc_current_locus = start_locus;
   gfc_next_char ();            /* Skip delimiter */


-- 
           Summary: MERGE intrinsic: Check for same string lengths
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


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

Reply via email to