PR 91800 - reject Hollerith constants as type initializer.
authorSteve Kargl <kargl@gcc.gnu.org>
Mon, 20 Apr 2020 11:21:38 +0000 (13:21 +0200)
committerThomas König <tkoenig@gcc.gnu.org>
Mon, 20 Apr 2020 11:21:38 +0000 (13:21 +0200)
2020-04-20  Steve Kargl  <kargl@gcc.gnu.org>
Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/91800
* decl.c (variable_decl): Reject Hollerith constants as type
initializer.

2020-04-20  Steve Kargl  <kargl@gcc.gnu.org>
Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/91800
* gfortran.dg/hollerith_9.f90: New test.

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

index 336ce49090eeaa0411642b9fdfba3b0fd342007d..2671c1aa38115ec9941943b22e3bb9e7ef42b37d 100644 (file)
@@ -1,3 +1,10 @@
+2020-04-20  Steve Kargl  <kargl@gcc.gnu.org>
+       Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/91800
+       * decl.c (variable_decl): Reject Hollerith constants as type
+       initializer.
+
 2020-04-19  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/93500
index b3ed63c97cc7c8efcdfaa6e95708af06133de4ce..d650407da4186025dd24bb99a17eefe14f6d8be4 100644 (file)
@@ -2903,6 +2903,15 @@ variable_decl (int elem)
       goto cleanup;
     }
 
+  if (gfc_current_state () == COMP_DERIVED
+      && initializer && initializer->ts.type == BT_HOLLERITH)
+    {
+      gfc_error ("Initialization of structure component with a HOLLERITH "
+                "constant at %L is not allowed", &initializer->where);
+      m = MATCH_ERROR;
+      goto cleanup;
+    }
+
   if (gfc_current_state () == COMP_DERIVED
       && gfc_current_block ()->attr.pdt_template)
     {
index 27ab5478d2981455d6a0e271ca29fc039fad1d2c..f8dba65ff9fed384c389e55adb8e2a1bbe79e310 100644 (file)
@@ -1,3 +1,9 @@
+2020-04-20  Steve Kargl  <kargl@gcc.gnu.org>
+       Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/91800
+       * gfortran.dg/hollerith_9.f90: New test.
+
 2020-04-19  David Edelsohn  <dje.gcc@gmail.com>
 
        * g++.dg/debug/dwarf2/pr85550.C: Skip AIX.
diff --git a/gcc/testsuite/gfortran.dg/hollerith_9.f90 b/gcc/testsuite/gfortran.dg/hollerith_9.f90
new file mode 100644 (file)
index 0000000..cfa1620
--- /dev/null
@@ -0,0 +1,7 @@
+! { dg-do compile }
+! PR 91800 - this used to cause an ICE.
+module m
+   type t(n) ! { dg-error "does not have a component corresponding to parameter" }
+      integer, len :: n = 4habcd ! { dg-error "Initialization of structure component with a HOLLERITH constant" }
+   end type
+end