re PR fortran/31266 (Spurious(?) warning about character truncation)
authorTobias Schlüter <tobi@gcc.gnu.org>
Thu, 12 Apr 2007 18:10:10 +0000 (20:10 +0200)
committerTobias Schlüter <tobi@gcc.gnu.org>
Thu, 12 Apr 2007 18:10:10 +0000 (20:10 +0200)
PR fortran/31266
fortran/
* primary.c (gfc_variable_attr): Don't copy string length if it
doesn't make sense.
* resolve.c (resolve_code): Clarify error message.
testsuite/
* gfortran.dg/char_assign_1.f90: New.

From-SVN: r123759

gcc/fortran/ChangeLog
gcc/fortran/primary.c
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog

index e99ccd15af7e42192faef703fb94cb43023f462a..ca2721c528441950eef60117896e12a6eaa91e19 100644 (file)
@@ -1,5 +1,10 @@
 2007-04-12  Tobias Schlüter  <tobi@gcc.gnu.org>
 
+       PR fortran/31266
+       * primary.c (gfc_variable_attr): Don't copy string length if it
+       doesn't make sense.
+       * resolve.c (resolve_code): Clarify error message.
+
        PR fortran/31471
        * decl.c (gfc_match_end): Also check for construct name in END
        FORALL and END WERE statements.
index 3044703357ac3fa9e28d4d3000c18949cf536d5f..1ef37a695512bb17c4909a2b673bbf7afe8cef51 100644 (file)
@@ -1844,7 +1844,14 @@ gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts)
       case REF_COMPONENT:
        gfc_get_component_attr (&attr, ref->u.c.component);
        if (ts != NULL)
-         *ts = ref->u.c.component->ts;
+         {
+           *ts = ref->u.c.component->ts;
+           /* Don't set the string length if a substring reference
+              follows.  */
+           if (ts->type == BT_CHARACTER
+               && ref->next && ref->next->type == REF_SUBSTRING)
+               ts->cl = NULL;
+         }
 
        pointer = ref->u.c.component->pointer;
        allocatable = ref->u.c.component->allocatable;
index f514e77df9ffae8366ab497b5cffb1f8964077a3..467ccf47681439dc263c379fd763a0e187f4378b 100644 (file)
@@ -5135,8 +5135,9 @@ resolve_code (gfc_code *code, gfc_namespace *ns)
                rlen = mpz_get_si (code->expr2->ts.cl->length->value.integer);
 
              if (rlen && llen && rlen > llen)
-               gfc_warning_now ("rhs of CHARACTER assignment at %L will be "
-                                "truncated (%d/%d)", &code->loc, rlen, llen);
+               gfc_warning_now ("CHARACTER expression will be truncated "
+                                "in assignment (%d/%d) at %L",
+                                llen, rlen, &code->loc);
            }
 
          if (gfc_pure (NULL))
index 8a409386fd895cf4f1664613f45606e59aef979e..2beab7818320305894fe058da7160089a16ee22a 100644 (file)
@@ -1,5 +1,8 @@
 2007-04-12  Tobias Schlüter  <tobi@gcc.gnu.org>
 
+       PR fortran/31266
+       * gfortran.dg/char_assign_1.f90: New.
+
        PR fortran/31471
        * gfortran.dg/block_name_1.f90: New.
        * gfortran.dg/block_name_2.f90: New.