]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/67803 (ICE on concatenating wrong character array constructor)
authorSteven G. Kargl <kargl@gcc.gnu.org>
Sat, 14 Nov 2015 17:31:16 +0000 (17:31 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Sat, 14 Nov 2015 17:31:16 +0000 (17:31 +0000)
2015-11-14  Steven G. Kargl  <kargl@gcc.gnu.org>

    PR fortran/67803
    * array.c (gfc_match_array_constructor): If array constructor included
    a CHARACTER typespec, check array elements for compatible type.

2015-11-14  Steven G. Kargl  <kargl@gcc.gnu.org>

    PR fortran/67803
    * gfortran.dg/pr67803.f90: New test.

From-SVN: r230379

gcc/fortran/ChangeLog
gcc/fortran/array.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr67803.f90 [new file with mode: 0644]

index a455b6bf5311217f35df544f66d3d3b547f80b1e..5fdb86687dfb5c2be6bd447462c01cc86f405010 100644 (file)
@@ -1,3 +1,9 @@
+2015-11-14  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/67803
+       * array.c (gfc_match_array_constructor): If array constructor included
+       a CHARACTER typespec, check array elements for compatible type.
+
 2015-11-13  Steven G. Kargl  <kargl@gccc.gnu.org>
 
        PR fortran/68319
index 144d8e0248703d998b109c6d0f6c9914d562b371..1e3f0f2b0abcfd1e714a1e9a84fb5350ddd42cca 100644 (file)
@@ -1162,6 +1162,35 @@ done:
     {
       expr = gfc_get_array_expr (ts.type, ts.kind, &where);
       expr->ts = ts;
+
+      /* If the typespec is CHARACTER, check that array elements can
+        be converted.  See PR fortran/67803.  */
+      if (ts.type == BT_CHARACTER)
+       {
+         gfc_constructor *c;
+
+         c = gfc_constructor_first (head);
+         for (; c; c = gfc_constructor_next (c))
+           {
+             if (gfc_numeric_ts (&c->expr->ts)
+                 || c->expr->ts.type == BT_LOGICAL)
+               {
+                 gfc_error ("Incompatible typespec for array element at %L",
+                            &c->expr->where);
+                 return MATCH_ERROR;
+               }
+
+             /* Special case null().  */
+             if (c->expr->expr_type == EXPR_FUNCTION
+                 && c->expr->ts.type == BT_UNKNOWN
+                 && strcmp (c->expr->symtree->name, "null") == 0)
+               {
+                 gfc_error ("Incompatible typespec for array element at %L",
+                            &c->expr->where);
+                 return MATCH_ERROR;
+               }
+           }
+       }
     }
   else
     expr = gfc_get_array_expr (BT_UNKNOWN, 0, &where);
@@ -1171,6 +1200,7 @@ done:
     expr->ts.u.cl->length_from_typespec = seen_ts;
 
   *result = expr;
+
   return MATCH_YES;
 
 syntax:
index 0b7f7ca81b04ea3e14a8f91a7aba3b1c14efc509..bed12411f365815343e013c5d4882c3ae679e897 100644 (file)
@@ -1,3 +1,8 @@
+2015-11-14  Steven G. Kargl  <kargl@gcc.gnu.org>
+       PR fortran/67803
+       * gfortran.dg/pr67803.f90: New test.
+
 2015-11-14  David Edelsohn  <dje.gcc@gmail.com>
 
        * g++.dg/cpp/ucn-1.C: Fix typo.
diff --git a/gcc/testsuite/gfortran.dg/pr67803.f90 b/gcc/testsuite/gfortran.dg/pr67803.f90
new file mode 100644 (file)
index 0000000..9a8ff30
--- /dev/null
@@ -0,0 +1,14 @@
+! { dg-do compile }
+! PR fortran/67803
+! Original code submitted by Gerhard Steinmetz
+! <gerhard dot steinmetz dot fortran at t-online dot de >
+!
+program p
+  character(2) :: x(1)
+  x = '0' // [character :: 1]       ! { dg-error "Incompatible typespec for" }
+  x = '0' // [character :: 1.]      ! { dg-error "Incompatible typespec for" }
+  x = '0' // [character :: 1d1]     ! { dg-error "Incompatible typespec for" }
+  x = '0' // [character :: (0.,1.)] ! { dg-error "Incompatible typespec for" }
+  x = '0' // [character :: .true.]  ! { dg-error "Incompatible typespec for" }
+  x = '0' // [character :: null()]  ! { dg-error "Incompatible typespec for" }
+end