re PR fortran/40875 (ICE with illegal type conversion)
authorPaul Thomas <pault@gcc.gnu.org>
Tue, 4 Aug 2009 12:41:08 +0000 (12:41 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Tue, 4 Aug 2009 12:41:08 +0000 (12:41 +0000)
2009-08-04  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/40875
* decl.c (add_init_expr_to_sym): Character symbols can only be
initialized with character expressions.

2009-08-04  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/40875
* gfortran.dg/initialization_23.f90 : New test.

From-SVN: r150454

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

index 45cec95..540d356 100644 (file)
@@ -1,3 +1,9 @@
+2009-08-04  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/40875
+       * decl.c (add_init_expr_to_sym): Character symbols can only be
+       initialized with character expressions.
+
 2009-08-02  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/40881
index 8dad9bf..86f41a3 100644 (file)
@@ -1253,9 +1253,13 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus)
          && gfc_check_assign_symbol (sym, init) == FAILURE)
        return FAILURE;
 
-      if (sym->ts.type == BT_CHARACTER && sym->ts.cl)
+      if (sym->ts.type == BT_CHARACTER && sym->ts.cl
+           && init->ts.type == BT_CHARACTER)
        {
          /* Update symbol character length according initializer.  */
+         if (gfc_check_assign_symbol (sym, init) == FAILURE)
+           return FAILURE;
+
          if (sym->ts.cl->length == NULL)
            {
              int clen;
index bd4ede1..3ee1adc 100644 (file)
@@ -1,3 +1,8 @@
+2009-08-04  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/40875
+       * gfortran.dg/initialization_23.f90 : New test.
+
 2009-08-04  Dodji Seketeli  <dodji@redhat.com>
 
        PR debug/39706
diff --git a/gcc/testsuite/gfortran.dg/initialization_23.f90 b/gcc/testsuite/gfortran.dg/initialization_23.f90
new file mode 100644 (file)
index 0000000..cc2aca4
--- /dev/null
@@ -0,0 +1,17 @@
+! { dg-do compile }
+!
+! PR 40875: The error was missed and an ICE ensued.
+!
+! Contributed by Michael Richmond <michael.a.richmond@nasa.gov>
+!
+    MODULE cdf_aux_mod
+      PUBLIC
+      TYPE :: one_parameter
+        CHARACTER :: name
+      END TYPE one_parameter
+      CHARACTER, PARAMETER :: the_alpha = one_parameter('c') ! { dg-error "Can't convert TYPE" }
+      CHARACTER, PARAMETER :: the_beta = (/one_parameter('c')/) ! { dg-error "Incompatible ranks" }
+    END MODULE cdf_aux_mod
+
+! { dg-final { cleanup-modules "cdf_aux_mod" } }
+